KevinnFtw Posted June 1, 2014 Share Posted June 1, 2014 Hey guys, I'm having some issues switching between states.In the first run it all works fine, but then when I come back to a state I've already been at, like MainMenu, the design is all messed up. I think it is because not all sprites and stuff are removed when I switch states, that's why I added a this.world.removeAll() in my shutdown function.However that doesn't seem to do anything. Is there another short way to delete everything (except cache) from a state before switching to another state, or does it have to be done manually? I've attached 2 images, one of my MainMenu first time, and one of the MainMenu when I switch back to it (after the Game). Excuse me if it is a silly question, I've just recently started using states.. Thanks,Kevin Link to comment Share on other sites More sharing options...
Loopeex Posted June 1, 2014 Share Posted June 1, 2014 Yeah I think you have to destroy all the sprites you added to the state.the removeAll function can take a "destroy" parameter, so give it a try : this.world.removeAll(true); Let us know =) KevinnFtw 1 Link to comment Share on other sites More sharing options...
KevinnFtw Posted June 2, 2014 Author Share Posted June 2, 2014 Thanks for your reply Loopeex :-) I've tried: shutdown: function() { this.world.removeAll(true);}But that doesn't make any difference unfortunately Link to comment Share on other sites More sharing options...
plicatibu Posted June 2, 2014 Share Posted June 2, 2014 add shutdown() function in each state and in it call the destroy() function of each and every element of the state. Link to comment Share on other sites More sharing options...
KevinnFtw Posted June 2, 2014 Author Share Posted June 2, 2014 Wait, isn't that what this.world.removeAll() is supposed to do?Doesn't that function destroy every element of the stage world? Link to comment Share on other sites More sharing options...
plicatibu Posted June 2, 2014 Share Posted June 2, 2014 I don't know. I always call destroy(). Wait, isn't that what this.world.removeAll() is supposed to do?Doesn't that function destroy every element of the stage world? Link to comment Share on other sites More sharing options...
KevinnFtw Posted June 2, 2014 Author Share Posted June 2, 2014 So you do like:sprite.destroy();player.destroy();enemy.destroy(); Do you destroy every element seperately? Link to comment Share on other sites More sharing options...
Recommended Posts