Sign in to follow this  
Polska296

How do you pass data to another scene?

Recommended Posts

I found that you could use this.scene.start('Scene2', {Level : 2, Health : this.hero.health}) to pass data to another scene. However the next step I see in every example online is what confuses me which uses init in the next scene to get the data. Any time I use init, I get an error saying either init or data is not defines. Would someone be able to show me an example of passing the data to another scene and then logging the data in the console when moving to the new scene?

 

 

Share this post


Link to post
Share on other sites

you need to pass data into the init function. So if you have

this.scene.start('game', { level: 1 })

then in your game scene you need

init(data){
  this.level = data.level;
}

 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.