HugoLuc Posted March 9, 2016 Share Posted March 9, 2016 Hi Guys, I'm running into this error message while trying to destroy an sprite or container: I Run into this problem even when destroying a simple bg image: function Round(){ this.score = 0; this.language = "english" this.background = PIXI.Sprite.fromImage('sprites/backGrounds/BackGround-01.png'); stage.addChild(this.background); } //LATER Round.prototype.destroy = function(){ this.background.destroy() } I have no idea what I'm doing wrong =/ Is there a specific way to destroy objects? Can anyone help? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 9, 2016 Share Posted March 9, 2016 You have to remove it from stage first: stage.removeChild(this.background); Why do you need to destroy containers anyway? Its only about textures and other stuff. Quote Link to comment Share on other sites More sharing options...
HugoLuc Posted March 9, 2016 Author Share Posted March 9, 2016 Interesting. What's the difference between removing and destroying then? That's a good question. I want to switch from one game to the other inside the website. The games use different textures from each other, so I thought that destroying the containers with their textures would free up some memory. What would be the best practice in this case? Thanks! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 9, 2016 Share Posted March 9, 2016 To free webgl videomemory of textures, you have to destroy texture or sprite containing it: //either that texture.destroy(true); //either that sprite.destroy(true, true); Container destroy() method will only free memory associated with Text and Mesh objects. Quote Link to comment Share on other sites More sharing options...
HugoLuc Posted March 9, 2016 Author Share Posted March 9, 2016 So if I have a bunch of texture inside the container I should call sprite.destroy() in all sprites individually? If I do "container.destroy(true)" wouldn't that destroy every element inside the container ( including the sprites and textures)? Btw, thank you! I'm new to pixi and I love it! This forum have been very helpful too! People reply really fast! =) Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 10, 2016 Share Posted March 10, 2016 Yeah, that's a problem: sprites inside container wont be called with (true, true) and textures wont be freed. Also you can find your textures in loader.resources (if you use it) or in PIXI.Texture.TextureCache, and call something like PIXI.utils.TextureCache["mystuff.png"].destroy(true); Thank you too! I hope to change that behaviour in v4, its not obvious now. Quote Link to comment Share on other sites More sharing options...
HugoLuc Posted March 10, 2016 Author Share Posted March 10, 2016 Thanks! That's really helpful! Yeah..., I guess It would be cool is destroy did all that work automatically. =) Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted March 10, 2016 Share Posted March 10, 2016 There will be special module for that later, it will check when was the last time specific texture used. 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.