Jump to content

Restart state problem


przemoo83
 Share

Recommended Posts

Hi I have a problem when I try to restart game when player dies. I do it like this

 if(playerHealth <= 0) {	this.game.state.restart();	} 

It works correctly because it restarts the stage hovever it keeps restarting itself over and over again as if the playerHealth was 0 all the time. This is strange because in this stage I declared global variable playerHealth = 100; so I don't think that is the problem. Any ideas?

Link to comment
Share on other sites

Hi, from my experience stateManager class will reset all of the sprites and stuff (because you probably placed them in the create method, not the constructor)

MyState = function(){  playerHealth = 100 //(default starting health)}MyState.prototype.create = function(){  playerVelocity = 50 //(initial player velocity)}

To get the desired behavior you should initialize your variables in create function, not your object function (the first function). That would indicate that phaser doesn't remake the whole state object. Having that in mind, you might want to clear every single variable at some point when resetting the state. You should look into the source code of phaser to find your answers, some things are easier to understand than you might think.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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