|
how to animate properly |
William Labbett
Member #4,486
March 2004
|
Hi, if(ball_moving) draw_ball(); if(fan_turning) draw_fan(); if(player_moving) draw_player();
In the draw_player() function there's a rest(10) call, so at the moment if the player is moving there's a rest(10) between every loop but if he's not the draw_ball() and draw_fan() get called quickly. I need to make so things are more consistent. Will
|
axilmar
Member #1,204
April 2001
|
Animation is not done at all in the way you describe. The appropriate approach is to do a balanced game loop like this: void int_proc() { ++timer; } install_int(proc, FPS(60)); while (game) { while (timer) { game_logic(); animate_stuff(); --timer; } draw_stuff(); } And then draw things in 'draw_stuff' and animate things in 'animate_stuff'. Animating is easy. For example, if you have a bitmap animation, all you need is an array of bitmaps and an index into the array: by increasing the index, your game object will be drawn differently each time it is drawn, i.e. be animated. Animation is all about altering the drawing parameters of a game object. |
William Labbett
Member #4,486
March 2004
|
Thanks axilmar. I think that should be install_int(int_proc, FPS(60)); but I get what you mean. I'll give this a go but I don't really understand what this code does. Is this right ? - While draw_stuff() is doing it's thing the timer integer gets Is that right ? Wouldn't this cause a lot of jumpy sprite drawing ? Thanks
|
axilmar
Member #1,204
April 2001
|
It might cause some jumping in slower computers, but generally it is one of the most used ways to code a game loop. |
William Labbett
Member #4,486
March 2004
|
Right.
|
|