views:

776

answers:

2

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?

+5  A: 

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.

Chris Farmer
This is correct. MouseMove isn't guaranteed to happen for every pixel the mouse moves. The best thing to do is draw a line from the last point to the current point, and if the user wants more detail they can draw slower, which forces the events closer together.
OwenP
When the mouse is moving 'fast' it is not because the events happen faster; it's because the mouse moves more pixels each time. Note that the cursor itself is not drawn in every pixel on the way.
configurator
A: 

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!!