Invalidating image too fast

184 Views Asked by At

I created simple app where the player moves the image to left and right. I am redrawing only the area of the player. But if the player holds the key, the movement is too fast and you cannot see the image moving fast rather than flickering "something". Any way to fix it? I am just beginning and am just 14 y/o so please bear with me. What I am doing is on the key down event I recognize the arrow and then add or subtract to player class X and Y properties. Based on that I invalidate the area around the player.

1

There are 1 best solutions below

3
On BEST ANSWER

If the main problem is flickering you want to be double-buffering (drawing to an area of memory - not the screen and then switching that area of memory to be drawn). Try setting these flags on your form (in its constructor):

SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);