jyapayne Posted March 18, 2014 Share Posted March 18, 2014 Hey, I'm trying to get my state to restart itself in phaser 2.0 when a player finishes the game. Currently, it kind of works, except some sprites and text are missing. The way I'm switching back is like this:game.state.start('StartScreen', true, true);But, like I said, it restarts the game with some text and sprites missing. Screenshots: StartScreen Before: StartScreen After: Game screen before: Game screen after: You can see in the game screen that the stars are missing and in the Start screen, all the text is missing. My question is this: Am I doing something wrong or is this a bug? I tried looking in the examples, but there are no examples for states. Link to comment Share on other sites More sharing options...
rich Posted March 18, 2014 Share Posted March 18, 2014 In your state swap you've set the 'clear cache' parameter to true. I'm pretty sure you don't want to actually be doing that. Clear world yes, but not the cache. Link to comment Share on other sites More sharing options...
jyapayne Posted March 18, 2014 Author Share Posted March 18, 2014 I've tried both the true and false settings in that call. They both lead to the same result. Link to comment Share on other sites More sharing options...
jyapayne Posted March 18, 2014 Author Share Posted March 18, 2014 I guess I should also mention that I'm calling this on overlap with two sprites.game.physics.arcade.overlap(this.spacecraft, this.level_end, this.end_level, null, this); and this is the end_level function now:end_level: function(craft, end_tile){ this.music.stop(); game.state.start('StartScreen', true, false); }, Link to comment Share on other sites More sharing options...
rich Posted March 18, 2014 Share Posted March 18, 2014 So you're not using a shutdown function to clear our sprites, check tweens have finished, all that kind of stuff? Link to comment Share on other sites More sharing options...
jyapayne Posted March 18, 2014 Author Share Posted March 18, 2014 I didn't know I had to. I thought that's what the resetWorld boolean was doing. Is there an example that I can reference? Link to comment Share on other sites More sharing options...
rich Posted March 19, 2014 Share Posted March 19, 2014 Could you get the new build from the dev branch on github and try it please? I've changed what happens during World destruction quite significantly and would like to see if it fixes this or not. https://github.com/photonstorm/phaser/tree/dev/build Link to comment Share on other sites More sharing options...
jyapayne Posted March 19, 2014 Author Share Posted March 19, 2014 Okay. I tried pulling the latest dev branch and still no luck. Same black screen. But lot's of the positioning code has been fixed, so that's awesome Is there anything I should be doing prior to changing state? Link to comment Share on other sites More sharing options...
rich Posted March 19, 2014 Share Posted March 19, 2014 In the new build it's now calling destroy on every single object in the world, so something obviously isn't starting up again quite right in your State. Do you get any errors in the console? Can you log out the missing/black objects and see where they are? (maybe check their z value, and x/y, and visible and alpha and stuff like that, to make sure they aren't just hidden somewhere). Link to comment Share on other sites More sharing options...
jyapayne Posted March 19, 2014 Author Share Posted March 19, 2014 Okay, cool, now we're getting somewhere. It seems that the game world size is not reset when restarting the state. That's my bad, I should have said that I resized the world. That matters because I set the text to appear at game.world.centerY and game.world.centerX. So that's fixed now by using the camera coordinates instead of the world. But the starfield is still messed up, so I have a question. When I switch states, does phaser call create() again? Juls and kctang 2 Link to comment Share on other sites More sharing options...
jyapayne Posted March 19, 2014 Author Share Posted March 19, 2014 Okay, I got everything working. I see that phaser does call create, but I wasn't clearing my array of star objects before I respawned them. Thank you so much for your help! Link to comment Share on other sites More sharing options...
rich Posted March 19, 2014 Share Posted March 19, 2014 Yes Phaser always calls 'create' when it starts a State. Which is why I said about using the 'shutdown' function to clear out local arrays, tweens, etc. That's an interesting point about the game world size not being reset. I think it probably ought to, so will do that. Link to comment Share on other sites More sharing options...
Recommended Posts