Jump to content

state and sprite bug


vjohansen
 Share

Recommended Posts

Hi

I modified one of the examples from the phaser tutorial to use states: playState -> nextLevelState -> playState -> ..

playState has the player and an enemy

nextLevelState shows the next level number and has a continue button

I use the init method to pass a level number.

Now when I start the playState for the second time some sprites are moving! ie. what happened playing level 1  is remembered when I start playstate with level 2 !

My enemy sprite moves even though I re-add the sprite in playState.create and my when i move the player I get:

 

Quote

Uncaught TypeError: Cannot read property 'velocity' of null
    at c.Physics.Arcade.moveToXY (phaser.min.js:24)
    at playState.update (game.js:303)
    at c.StateManager.update (phaser.min.js:10)

 

I use game.state.start('NextLevelState', true, false, current_level); //clearWorld=true

and  game.state.start('playState', true, false, current_level);
 

What am I missing regarding states and recreating sprites (game.add.sprite)?

 

Link to comment
Share on other sites

The problem was phasers crappy documentation.

When a state is started again you have make sure your member variables are reset properly in the create call.

 

i had a list (this.players = []) which only where appended t in create() so it would end up with extra elements. fix is to add this.players = [] in create(..)

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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