Achieving animation speed with timers

Hello,

I’m trying to create the game Frogger in java. I’m using timers to generate action events which call repaint, and get the car to move across the screen. The problem is that the car goes pretty fast at first but slows down as time passes. An even more serious problem is that the car stops whenever the frog moves (I have a key listener that makes the frog move).

Any help would be appreciated, maybe I’m going about this the wrong way?

can’t help with your car problem without seeing the code. with your game - you normally want a single-threaded “game loop”. Any actions such as moving the frog should enter a queue. actions like moving the frog will be processed over several game loops.

for example you can could store info on where the frog is meant to be - and the current pixel of where he is at. Each frame (game loop iteration) move the frog closer. Also each frame, the cars would move too.

Sorry for the quick explanation, but I think that’s what you want to do. Generally you don’t want several threads executing the game code at once (using them for events like Swing does is fine).

Will.