So game progress has been going quite nicely:
LzLgQsTy0V0
But I’ve noticed something – the actual game’s backgroundmusic and the heartbeat sound plays in the menu state.
So I’ve tried to make all the stuff for the actual game (such as the backgroundmusic and the heartbeat) init only if the game is in the play(actual game) state (which is 2).
Play.java:
if(sbg.getCurrentStateID() == 2){
// Images
map = new Image("resources/Images/Backgrounds/backGround_two.png");
// Music
backGroundMusic = new Sound("resources/Music/BGM/eerie.wav");
backGroundMusic.loop();
// HUD BLOCK START
hudGUI = new HUD();
healthGUI = new Health();
healthGUI.init(gc);
inventoryGUI = new Inventory();
inventoryGUI.init(gc);
// HUD BLOCK END
mainPlayer.getWeapon().init(gc);
}
But that doesn’t work.
So I’ve made a breakpoint in the Menu’s update method, and a breakpoint for that if statement in the play class – debugged – the play class’ if statement is met first
and THEN the update method is met.
Quite strange.
Here’s how the “main game” (not the “actual game state”, which is Play.java, sorry if all these names are confusing :S) class is setup:
Game.java:
public void initStatesList(GameContainer container) throws SlickException {
// 0
ResourcesState rs = new ResourcesState();
states.add(rs);
addState(rs);
// 1
Menu menu = new Menu();
states.add(menu);
addState(menu);
// 2
Play play = new Play();
states.add(play);
addState(play);
// 3
Credit credits = new Credit();
states.add(credits);
addState(credits);
}
Any suggestions?