ManBoy Posted August 19, 2015 Share Posted August 19, 2015 MainMenu = function(){ this.background; }; MainMenu.prototype = { create:function() { console.log(this.background); if(!this.background) { this.background = this.add.image(0,0,'PreloadAtlas','Background_Cloud.png'); } var playButton = this.add.button(this.world.centerX,this.world.centerY - 175,'GameAtlas',this.playButtonClick,this,'Play_Button-0002.png','Play_Button-0001.png'); playButton.anchor.set(0.5); }, shutdown:function() { //this.background.destroy(); //this.background = null; }, playButtonClick:function() { this.state.start('GamePlay',true); } }; How do I properly clean up objects after each state? The reference of 'this.background' is still there, but is the image gone from memory? I'm asking because if I need to destroy every display object and set it to null, I'm not planning to use any local variable (e.g: playButton) for display objects. Sorry for newbish question. Link to comment Share on other sites More sharing options...
tips4design Posted August 19, 2015 Share Posted August 19, 2015 The image is stored inside the texture cache and is persistent between states (eg: stays in the cache from the moment you load it until you specifically remove it) Link to comment Share on other sites More sharing options...
glantucan Posted August 19, 2015 Share Posted August 19, 2015 Depends on what you mean. The image object is gone, but its texture is still on the cache as tips4design says. But you can avoid that if you set the proper flag when starting the next state (see this):this.state.start('GamePlay',true, true); Link to comment Share on other sites More sharing options...
Recommended Posts