Jump to content

【question】: does phaser have the callback when game state changes


scofieldly
 Share

Recommended Posts

Hi all, 

currently I got problem that

I have a websocket thread to communicate with the server. and the game object is also start in the process, the situation is like this.

when I got the response: A from the server, I will change the game to a new state by

game.state.start('NEW STATE');

and then I will get the response: B, C from server, then I need to run some functions defined in the new state, like this

game.state.callbackContext.function_in_new_state();

but it is not working, then I loged the state  

game.state.current

I found that the current state is still the OLD ONE.

I know the state change need some time, BUT is PHASER provide any callback method when the current state changed to another one, 

thx everyone.

Link to comment
Share on other sites

Hi, sorry, I might not be the best person to answer your question, but why isn't the state change synchronous?

I assumed you told it to change state, it maybe ran a 'destroy' or 'clean up' (create/init) function on the old state and any 'before' or 'prep' (shutdown) functions on the new one but that these were all synchronous and I didn't think there was any way of changing that behaviour without major modifications to the Phaser state code, have you made these changes? or maybe I've got it wrong and Phaser state changes use promises or callbacks or some other mechanism to say when they are done?

I just had a poke through some examples (which were old) and the current docs and codebase, they look pretty synchronous, which means you know exactly when they change because you control it, I could still be wrong about that though, it was only a quick look around in there.

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...