Hi, sorry for the nooby question but I have a stateBasedGame and recently in some classes I put in a System.out.println(“This class has finished loading”);
The problem is that I get two messages for each class, meaning that each of the init() methods are being called twice.
Did I do something wrong with my code or is this how Slick2D is set up?
Part of my main class
public PsionicEntrance(String NAME) {
super(NAME);
for (int i = 0; i < players.length; i++) {
players[i] = new Player();
}
this.addState(new Menu(MENU, players));
this.addState(new Options(OPTIONS, players));
this.addState(new Play(PLAY, players));
this.addState(new CharacterEdit(CHARACTEREDIT, players));
this.addState(new Credits(CREDITS, players));
this.addState(new Rhombus(RHOMBUS, players));
}
public void initStatesList(GameContainer gc) throws SlickException {
GameSound.init();
this.getState(MENU).init(gc, this);
this.getState(OPTIONS).init(gc, this);
this.getState(PLAY).init(gc, this);
this.getState(CHARACTEREDIT).init(gc, this);
this.getState(CREDITS).init(gc, this);
this.enterState(CURRENTSTATE);
}
Example of an init method that’s being called twice
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
credits = new Image("res/image/credits.png");
System.out.println("Credits finished loading!");
}
Thank you for any help you can provide!
EDIT: I just noticed that I didn’t call “this.getState(RHOMBUS).init(gc, this);”, that’s weird how I got no errors with that, also without this, rhombus init() is only called once, I suppose I need to read more documation of Slick2D :X.