In one of my game, I have an issue when I restart my state, the position of the player is wrong. I spent a long time to isolate the bug and create a minimal example here: http://phaser.io/sandbox/SUEwRegw
If you press the space key, the camera moves and the circle is on the left of the screen. I you press the "R" key, the state is restarted (with a game.state.restart();) but the circle is not at the same position than on the first start, if you press again the "R" key the circle is at the correct position.
I use a bitmapData to draw a circle, because if I load a picture sometimes the bug doesn't occur. (It depends the picture loading time, with a local image the bug always occurs.)
The issue is in the method Phaser.Physics.Arcade.Body.checkWorldBounds. When the state is reloaded, the x position of the sprite is negative, so the condition (position.x < game.physics.arcade.bounds.x) is true then the position of the sprite is set to 0 (the value of this.game.physics.arcade.bounds.x) and finally the sprite isn't at the expected position.
I didn't find any workaround, and it's a too complex bug for me to fix it.
Wow that was a tricky one to track down, but a thankfully very easy fix! The dev branch fixes this - thank you for the really helpful issue report, it was the only thing that allowed me to resolve it!
In one of my game, I have an issue when I restart my state, the position of the player is wrong. I spent a long time to isolate the bug and create a minimal example here: http://phaser.io/sandbox/SUEwRegw
If you press the space key, the camera moves and the circle is on the left of the screen. I you press the "R" key, the state is restarted (with a game.state.restart();) but the circle is not at the same position than on the first start, if you press again the "R" key the circle is at the correct position.
I use a bitmapData to draw a circle, because if I load a picture sometimes the bug doesn't occur. (It depends the picture loading time, with a local image the bug always occurs.)
The issue is in the method Phaser.Physics.Arcade.Body.checkWorldBounds. When the state is reloaded, the x position of the sprite is negative, so the condition (position.x < game.physics.arcade.bounds.x) is true then the position of the sprite is set to 0 (the value of this.game.physics.arcade.bounds.x) and finally the sprite isn't at the expected position.
I didn't find any workaround, and it's a too complex bug for me to fix it.