Zendrael Posted November 23, 2015 Share Posted November 23, 2015 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 More sharing options...
shohan4556 Posted November 23, 2015 Share Posted November 23, 2015 yes you can easily do it with Phaser using state here is a very helpful tutorial about this http://gamedolph.in/tutorials/state-management-tiny-tutorial/ Link to comment Share on other sites More sharing options...
Zendrael Posted November 23, 2015 Author Share Posted November 23, 2015 Hi Shohan! I can swicth between states, it just doesn't redraw what was on the previous one, for example the background. How can I draw an element from the previous one? Link to comment Share on other sites More sharing options...
in mono Posted November 24, 2015 Share Posted November 24, 2015 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 More sharing options...
Zendrael Posted November 24, 2015 Author Share Posted November 24, 2015 Hi! So, in the create function of the title stage I didPLAYER = 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 More sharing options...
in mono Posted November 24, 2015 Share Posted November 24, 2015 You can change the state without clearing the world (look at the docs for game.state.start()), but that doesn't seem like a good practice to me. Link to comment Share on other sites More sharing options...
Zendrael Posted November 24, 2015 Author Share Posted November 24, 2015 Ok everyone! Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts