Note that there are some explanatory texts on larger screens.

plurals
  1. POslick 2d, Java, Animation getters and setters
    primarykey
    data
    text
    <p>i'm trying to develop a game and it's still early days, but i've run into an issue.</p> <p>I've created a character class and defined an animation in that class but want to use it in another class, I've made a getter for the Animation, but in the class where i want to use it, it's just returning null. The getters and setters work just fine with integers, but i cant figure this out, any help would be appreciated :)</p> <p>Player class</p> <pre><code>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.SpriteSheet; import org.newdawn.slick.state.StateBasedGame; public class Player { int x,y,dx,dy; Animation currentAnim, DownWalk, LeftWalk; SpriteSheet down; public Player(int x, int y) throws SlickException{ this.x = x; this.y = y; currentAnim = DownWalk; } public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { down = new SpriteSheet("res/Character/DownWalkSpriteSheet",160,160); DownWalk = new Animation(down, 200); currentAnim = DownWalk; } public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { Input input = gc.getInput(); } public void render(GameContainer gc, StateBasedGame arg1, Graphics sbg) throws SlickException { currentAnim.draw(100,100); } public Animation getAnim(){ return currentAnim; } public int getX(){ return x; } public int getY(){ return y; } } </code></pre> <p>Level class(the class i want to use it in):</p> <pre><code>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.GameState; import org.newdawn.slick.state.StateBasedGame; public class Room1 extends BasicGameState { Image Room1; Player player; public Room1(int state){ } @Override public void init(GameContainer gc, StateBasedGame sbg) throws SlickException { Room1 = new Image("res/Room1.png"); player = new Player(300,300); } @Override public void render(GameContainer gc, StateBasedGame arg1, Graphics sbg) throws SlickException { Room1.draw(0,0); } </code></pre> <p>the system.out.print is how i checked that it was returning null</p> <pre><code>@Override public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException { System.out.println(player.getAnim()); } @Override public int getID() { // TODO Auto-generated method stub return 1; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload