Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Animation more fluid?

Status
Not open for further replies.

kecos

Programmer
Jan 30, 2009
1
0
0
US
I'm working on a simple game, and I need help with making the animation more fluid. The way it's set up now, if I hold a key, it moves once, freezes, then moves fast. Is there any way I can just make it move at a set speed while the key is held down?

Here is the code for using the up arrow key to move the character up:
Code:
        Clock.Interval = 40;
        if (keyEvent.KeyCode == Keys.Up)
        {
            keyLastPressed = 2;
            if (y > -10)
            {
                y -= 10;
            }
            Invalidate();
        }
 
Try placing your code in the KeyDown event.

Also, you may want to read about double-buffering to optimize rendering operations. One technique is to draw first on a memory resident buffer (eg bitmap), then render the image to the screen (eg form).

my 2cents
 
Agreed, keying off the key-pressed/released events will be better than relying on the O/S to fire multiple keystroke events. Regarding the double buffering, I've had best results by running two threads, one controlling the model and one controlling the rendering. Basically you have a handle to the model. The model thread writes a temporary model and then updates the handle. The rendering thread performs the graphical double buffering, keying off the model handle. This approach divorces your logical execution speed from your FPS.

"If debugging is the process of removing bugs, then programming must be the process of putting them in." --Dykstra
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top