Java Slick2d Animation not working

Posted by user3558075 on Game Development See other posts from Game Development or by user3558075
Published on 2014-05-26T21:41:20Z Indexed on 2014/05/26 22:05 UTC
Read the original article Hit count: 455

Filed under:
|

Hello everyone I am trying to make a simple 2d game using java and the slick2d library. this is my first time doing it and i need some help. right now I am trying to make the Animations for the character, so that when you go right he turns right and when you go left he turns left... but I keep getting an error when im drawing the character, ive try'd re-downloading slick but that didnt work. when i get rid of the player.draw(x,y); line of code it dosen't crash but the character isnt there. heres my code, can anyone help?

package enteties;

import input.Keyinput;

import org.newdawn.slick.Animation; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.Image; import org.newdawn.slick.Input; import org.newdawn.slick.SlickException; import org.newdawn.slick.state.BasicGameState; import org.newdawn.slick.state.StateBasedGame;

import playerinfo.Playerinfo;

public class Player extends BasicGameState{

Playerinfo pi = new Playerinfo();
Keyinput ki = new Keyinput();

Animation player,up,down,left,right;




public void init(GameContainer gc, StateBasedGame sbg)
        throws SlickException {
    Image[] goingUp = {new Image("res/buckysBack.png") , new Image("res/charBack.png")};

    Image[] goingDown = {new Image("res/buckysFront.png") , new Image("res/charFront.png")};

    Image[] goingLeft = {new Image("res/buckysLeft.png") , new Image("res/charLeft.png")};

    Image[] goingRight = {new Image("res/buckysRight.png") , new Image("res/charRight.png")};

    int[] duration = {200,200};

    Animation up = new Animation(goingUp,duration,false);
    Animation down = new Animation(goingDown,duration,false);
    Animation left = new Animation(goingLeft,duration,false);
    Animation right = new Animation(goingRight,duration,false);
    player = up;



}


public void render(GameContainer gc, StateBasedGame sbg, Graphics g)
        throws SlickException {

    //error happens here, when i remove this line it dosent crash
    player.draw(720,450);



}


public void update(GameContainer gc, StateBasedGame sbg, int delta)
        throws SlickException {


}



public int getID() {

    return 0;
}

}

© Game Development or respective owner

Related posts about java

Related posts about slick