|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionWhile writing a game which I will hopefully release later on here, I had to find a way to reduce flicker. I also ran into the problem of the redraws causing the game to move extremely slow. I did some research and found out about DoubleBuffering, Timers and PaintEvents. I hope you learn from this as much as I did. Step1: Making the Timer
Step2: Make a Paint EventNow we need to make a paint event that will draw our images for us. So we do the following:
Step 3: Make Our VariablesNow we need some variables to control our movement. We also need an image to draw and a X co-ordinate that I will explain.
*****Make sure the FASTCAR.GIF is in the debug or release folder********** Step 4: Turn on Double BufferingWe now turn on double buffering to prevent flicker. Include the following code in the SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
Step 5: Compile and RunAgain make sure that the fastcar.gif is in your debug or release folder depending on which build configuration you have selected. Conclusion:I hope this helps you as much as it did me.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||