Jump to content

Problem with loading a state after completing level.


Voltiac
 Share

Recommended Posts

Hello everyone,

I am working on a project on the old Phaser 1.1.3 framework. I'm a bit too far into this project to grab a newer one I think.

 

My problem is that after I reach the end of the level I want to start a state, but the state shows blank/white.
The project has the globally known structure Boot > Preloader > MainMenu and then goes to LevelOne.
When the the level is complete the following code get executed:
 

stopAnim(this, 0);
destroy();
alert("You have won the game!");
this.game.state.start("SelectionScreen");
 
I print a message in every state, this way I know what state has been loaded. In the console I get the following message:
✔✔ Level Selection Ready! ✔✔ SelectionScreen.js:16  
 
But somehow the screen goes to blank/white. 
I also tried loading the Boot state again, but this gave the same result: the white screen.

What could be the potential problems?

 

Link to comment
Share on other sites

So it works getting from Boot, to Preloader, to MainMenu, to LevelOne - but can't get any further? I would say something in your shutdown / destroy block is causing it to be honest, as I can't see a reason why the StateManager would happily work across the first 4 states but fail on the 5th.

Link to comment
Share on other sites

Yes, I can go through all the states without any problem, I can navigate forward and backward. I also start the game without any problems, but when I come to the end of my level It turns up blank. This is my console output:

 

MainMenu.js:12  ✔✔ Main Menu ready! ✔✔
phaser.min.js:6 InputHandler start
phaser.min.js:6 InputHandler start
phaser.min.js:6 InputHandler start
phaser.min.js:9 No FrameData available for Phaser.Animation run << This is because I use a wrong image at the moment
SelectionScreen.js:16  ✔✔ Level Selection Ready! ✔✔
phaser.min.js:6 InputHandler start
 

But the second last line, selectionscreen gets initialized after finishing the level, it doesnt matter which game I start, it's just plain white.
 

Link to comment
Share on other sites

State.shutdown is the method you should use for all destruction related events.

 

Also this:

                if(this.won == true) {                    alert("You have won the game!");                    this.game.state.start("SelectionScreen");                }

Is pretty dangerous stuff - there is every chance the State.start would be called multiple times as it's part of an update loop. When you call State.start it doesn't immediately swap state, it queues it up ready to be processed at the right time, which means this could execute several times. I would refactor it to remove any State swapping from any frequently called function.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...