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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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