Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 1:21 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Jul 05, 2009 8:04 am 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
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?

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 05, 2009 8:25 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Sounds bugged to me.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 11, 2009 11:36 pm 
Offline
Regular

Joined: Sun Dec 07, 2008 5:22 am
Posts: 238
Location: Vancouver, BC, Canada
Okay so I think I tracked down the problem.
Not really with auto-update but the restart method not doing what it should.

So this is what the restart method is doing:
Code:
   public void restart() {
      if (!stopped) {
         return;
      }
      
      if (frames.size() == 0) {
         return;
      }
      stopped = false;
      currentFrame = 0;
      nextChange = (int) (((Frame) frames.get(0)).duration / speed);
   }

But it fails to properly set the lastUpdate field.
The following will fix the problem:
Code:
   public void restart() {
      if (!stopped) {
         return;
      }
      
      if (frames.size() == 0) {
         return;
      }
      stopped = false;
      currentFrame = 0;
      nextChange = (int) (((Frame) frames.get(0)).duration / speed);
      firstUpdate = true;
      lastUpdate = 0;
   }


Kind of off topic but I also think it's dumb that restart only actually restarts the animation if its stopped. If I tell it to restart I want it to restart not maybe restart. It's not like it's hard to check for myself if its stopped. Along the same lines it seems weird that the animation starts playing automatically when you restart it. To me it would make the most sense for calls to animation.isStopped() to return the same value before and after calls to animation.restart() are made.

_________________
If at first quads don't succeed tri tri again.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 15, 2009 9:57 am 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Resolved in SVN including the suggested that restart always restarts.

Off topic - it's not really dumb, wrong or broken sure, but dumb implies stupidity (if thats what you meant then ok :))

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group