Jump to content

State still with game properties after change state


PRSoluções
 Share

Recommended Posts

Another problem is the GameState properties. When TitleState send me to GameState the previous properties remain o.o and the player is duplicated. Look:

Screenshot 2016-03-30 13.59.16.png

1 - When my code call GameState.init i execute:

console.log(this.players);
this.players = {};
this.player = null;
console.log(this.players);

The first time on console:

undefined and {}

Backing to title and going to game again, on console:

Object {} and Object {}

Too strange.

 

 

 

 

 

 

 

Link to comment
Share on other sites

Two things, one this may be caching issue, see here to clear cache on state change: http://phaser.io/docs/2.4.4/Phaser.StateManager.html#start

What I think is the actual issue, just looking briefly at your code, is when you set this.players inside a state, you set that object up inside the state object. you could set this back to null on the shutdown method, provided by phaser states, that gets called when the state is ended.

i.e: 

init() {
    this.players = {};
}

create() {
    
}

update() {

}

shutdown() {
    this.players = null;
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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