Sign in to follow this  
ghigared

Slick 2D Rendering Animation Trouble

Recommended Posts

ghigared    133

I've been working with Slick2d for a few weeks now and I really enjoy it (since I'm a native Java developer). I began development of a small game, but my animation rendering isn't working the way it's suppose to. The following is my code for the class where I'm having trouble:

 

public class Player extends Entity{
    private int duration = 600;
    Animation tmp = new Animation();

    public Player(int x, int y, int w, int h) {
        super(x, y, w, h);
    }

    @Override
    public void render(GameContainer gc, Graphics g) {
        setAnimations();
    
        g.drawAnimation(tmp, 100,100);
    
    }

    @Override
    public void update(GameContainer gc) {

        if(tmp.isStopped()){
            tmp.start();
        }
        else
            tmp.stop();
    }

    @Override
    public void setAnimations() {
        Image[] tempImage = new Image[3];
        
        for(int i = 6, j = 0; i < 9; i++){
            tempImage[j] = prototypeCo2Graphics.spriteSheet[i][0];
            j++;
        }
        
        //tmp.addFrame(prototypeCo2Graphics.spriteSheet[5][0],duration);
        for(Image i : tempImage)
            tmp.addFrame(i, duration);

        animations.add(tmp);
    }

}
 

What happnes is that the image renders unto screen, but the animation is way too fast. (Frame 1 display longer, and Frame 2 and 3 simply just flash). Any Help would be greatly appreciated, thank you.

Share this post


Link to post
Share on other sites
KnolanCross    1974

Not knowing this lib the only thing that comes to my mind is that duration is the time to switch the frame, not the time the frame should last. If that would be the case it would run the first from 0 to 600 (probably ms), and the other two from 600 to 600 (in this case, would just flash).

 

Have you tried seting the duration to 600, 1200, 1800? Also, have you check if the values are really correct? Maybe something is changing it.

Edited by KnolanCross

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this