Jump to content

Reusing elements


Zendrael
 Share

Recommended Posts

Hello!

 

In my Title Stage I added a background and a button to start the game. When the button is pressed it goes to the Stage named Play where all the logic must happen. But all goes black/blank.

 

How can I go from one stage to another without recoding all my sprites and images from the title? Is there some way to just add them on the new stage?

 

Thanks!

Link to comment
Share on other sites

The more sensible approach would be to draw the background again in the new state. If it needs a lot of adjustments, you may wrap it in a function that you will call from all the states you need.

 

If the background will be the same all across the game, you may also draw it in the DOM and only use Phaser for the actual game.

Link to comment
Share on other sites

Hi!

 

So, in the create function of the title stage I did

PLAYER = GAME.add.sprite( 30, 112, 'player');

and it automatically draws the player when in that state. When I go to the new state after clicking a button, I want to maintain this sprite (or background or other stuff) without having to instantiate this variable again.

 

How can I reuse this sprite/var in the new state? I tried to use the GAME.add.existing( PLAYER ) but it didn't worked...

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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