nmiguelmoura Posted May 31, 2016 Share Posted May 31, 2016 Hi all! I'm building an edu app that will be packed with cordova. In one of the scenes, there is a bunch of small objects in stage. When an object is pressed, a hi-res texture of that object appears in the screen. This hi-res image is loaded only when the object is pressed with the following code: var self=this; //this object inherits from Sprite //loader is a PIXI.loader loader.add('bigTexture',imgPath); loader.load(function(){ self._currentTexture=PIXI.Texture.fromImage(imgPath); self.texture=self._currentTexture; }); As soon as the user dismisses the image, it disappears from screen and the texture must be destroyed. The user can than click on the same object or on another one and the process restarts. To destroy the texture and remove it from loader i use this code. this.parent.removeChild(this); //removes sprite from stage delete (loader.resources['bigTexture']); this._currentTexture.destroy(true); this._currentTexture=null; I have two questions, and would be great if someone could help: Is this the correct way to do this? I mean, load texture, destroy texture, remove from loader to allow reloading again? Thanks for your help, Nuno Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 31, 2016 Share Posted May 31, 2016 Your solution is acceptable, however best solution depends on your game type. Dont forget that sometimes PIXI puts stuff in PIXI.utils.TextureCache, I suggest you to clear it after loader completes. The other thing is that Pixiv4 has GC that takes care of webgl textures that werent used for a long time, so its not a tragedy if you forget to call texture.destroy(true); I'm solving this kind of problem for RPGMaker MV and its not easy: For each scene you have to create a loader with specific textures for that scene. When user exits it, you just free all the specific textures. If new scene has some of old resources, just move them instead. I also have special cache with TTL for streamed and big resources. nmiguelmoura 1 Quote Link to comment Share on other sites More sharing options...
nmiguelmoura Posted May 31, 2016 Author Share Posted May 31, 2016 Thanks Ivan, Like always, you were a big help. Good to know the code is fine. I didn't knew i could create more than one loader, i keep using the same one. Thanks, Nuno Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 31, 2016 Share Posted May 31, 2016 21 minutes ago, nmiguelmoura said: Thanks Ivan, Like always, you were a big help. Good to know the code is fine. I didn't knew i could create more than one loader, i keep using the same one. Thanks, Nuno Yes, you can just "forget" about previous scene and its loader, and it will be collected by javascript GC, while pixi gc will handle videomemory part. You can also manually run that garbage collector between scenes or when the game is paused: renderer.textureGC.run(). It will find textures that werent used for 60 seconds or so. Quote Link to comment Share on other sites More sharing options...
nmiguelmoura Posted May 31, 2016 Author Share Posted May 31, 2016 That's great info. I'll try that. Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.