I am having a problem with Animations using auto update.
The animation is non looping, and gets played as a result of numerous events. The first time the animation is played it runs fine, but every subsequent time only the last seconds of the animation play.
Near as I can tell when it draws the last frame it sets the private field "lastUpdate" to the current time. Then sometime later when the I request the animation to be replayed by calling animation.restart(); instead of setting "lastUpdate" to 0 and resetting "firstUpdate" to true, it leaves them as they are. This causes the animation class to try to resolve what frame it should be on based on the elapsed time, skipping as many as necessary.
The following is an example
Code:
public class Test extends BasicGame{
Animation anim;
public Test(){
super("Animation AutoUpdate Test");
}
public void init(GameContainer arg0) throws SlickException{
anim = ..... //load animation here
anim.setLooping(false);
}
public void update(GameContainer container, int delta) throws SlickException{
Input input = container.getInput();
if(input.isKeyDown(Input.KEY_X) && anim.isStopped()){
//anim.draw();
anim.restart();
}
}
public void render(GameContainer arg0, Graphics arg1) throws SlickException{
if(!anim.isStopped()){
anim.draw(50, 50);
}
}
public static void main(String[] args){
try{
AppGameContainer app = new AppGameContainer(new Test());
app.setDisplayMode(500, 400, false);
app.start();
}catch(SlickException e){
e.printStackTrace();
}
}
}
Note the commented line "anim.draw()" when uncommented causes the animation to play normally. But this is really kludgey.
So my question is: Am I missing something simple or do I need to raise a Bug?