oliversb Posted October 25, 2014 Share Posted October 25, 2014 How do I keep sprites alive while switching from one state to another? Thanks Link to comment Share on other sites More sharing options...
oliversb Posted October 25, 2014 Author Share Posted October 25, 2014 - Link to comment Share on other sites More sharing options...
c023-dev Posted October 26, 2014 Share Posted October 26, 2014 You could maybe try *without* switching states. Clear only your unwanted data (like the level, groups etc.) and re create/ re position old sprites within the same state.Or you could pass through data when creating a new state like:goEndScreen() { this.game.state.states['EndGame'].count_deaths = this.count_deaths; //make the data match this.game.state.start('EndGame', true, false); //then load the state }//I guess you might be able to pass through sprites like this too?!I think a built-in persistent state data is a feature still in development. (Sub-States) The complicated way would be to save your persistent data within a database on your web server ... I'd love to know how to do that... Link to comment Share on other sites More sharing options...
JUL Posted October 26, 2014 Share Posted October 26, 2014 Actually you can't, as phaser is made today. It's on the roadmap however, to include persisting states. A solution could be an object where you store players data such as life, weapon type, score, previous state name, etc... That you update each time a state is left. Link to comment Share on other sites More sharing options...
jouniii Posted October 27, 2014 Share Posted October 27, 2014 Afair the state change clears the world. You might get around adding directly to stage (or creating own persisting world group which is in stage). However the stage change clears also timers which maybe problem. I made workaround for timer clearing making my objects to resume timers when state changes. Also make note that there are points to take care to destroy() your objects manually to let GC take over. Link to comment Share on other sites More sharing options...
Recommended Posts