Jump to content

Switching States Back In Phaser 2.0


Recommended Posts

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.




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

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

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?

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.

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.


  • Recently Browsing   0 members

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