Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MouseMove event too slow for painting

I'm using C# WinForms to create a level builder for my XNA game. I have a tile grid that you can paint with a Pencil tool, like in MSPaint. The problem is that when you drag the mouse fast(ish) to paint a line tiles get skipped.

I've tried using one approach i saw on Google saying to spawn a thread to do the painting, but that didn't seem to help.

Any ideas?

like image 657
James Petruzzi Avatar asked Dec 31 '08 21:12

James Petruzzi


2 Answers

OTTOMH, you could keep track of the last point the mouse was and in your MouseMove handler you can assume linear motion and determine all the tiles between the last point and the current point. My guess is that you're not likely to ever get enough MouseMove events to fire to handle the case where the user moves his mouse very quickly.

like image 146
Chris Farmer Avatar answered Nov 06 '22 12:11

Chris Farmer


Awesome! worked perfectly.

I used the DDA line algorithm from here

http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html

to draw the line.

Thanks!!

like image 38
James Petruzzi Avatar answered Nov 06 '22 13:11

James Petruzzi