I'm using a swing timer to animate a figure movement in my game. It's working fine if I send it from one point to another, but when I call it multiple times, the animation speed adds up.
I think it has to work this way, but can I "stack up" timers to only start the upcomming when the current animation finished?
It's not the exact code but works like this:
Timer timer = new Timer(40, new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(figure.x != target.x){
if(figure.x < target.x){
figure.x+1;
}else{
figure.x-1;
}
}
}
});
timer.start();