neonwarge04 Posted August 19, 2015 Share Posted August 19, 2015 I want to remove all children on my Container when the game ends to make way for a new scene. unfortunately I can't make it to work.Here's how I did it. I read it from the documentation and it states there that the `destroyChildren` param is set to 'true' on `PIXI.Container.destroy(destroyChildren)` will also destroy its children. But when I call this code: this.mOnFinishCallback = function(){cancelAnimationFrame(this.mAnimationFrameID);this.mContainer.destroy(true);};The entire scene just stops and I can still see objects. This is not what I want. I wanted to have my sprites to go away.How am I suppose to do it? Thanks! Quote Link to comment Share on other sites More sharing options...
xerver Posted August 19, 2015 Share Posted August 19, 2015 Because you canceled the animation loop, so the last rendered frame is shown which was all those objects. Quote Link to comment Share on other sites More sharing options...
neonwarge04 Posted August 19, 2015 Author Share Posted August 19, 2015 So, How do I do it? If I do remove the sprites before I cancel the loop it crashes on one of pixi code saying the 'children' on variable is undefined.`Uncaught TypeError: Cannot read property 'length' of null` this happens on pixi.js line 24946. That's why I destroyed it first before I cancel the loop. My assumption is, maybe the loop has been called one more time, for the last time and that the sprite it suppose to update was no longer there.`for (var i = this.mStage.children.length - 1; i >= 0; i--){this.mStage.children = false;//this.mStage.removeChild(this.mStage.children);}` I tried to this but, the sprite is still there. This time I just wanted to hide the sprite. That's all. Thanks! Quote Link to comment Share on other sites More sharing options...
neonwarge04 Posted August 19, 2015 Author Share Posted August 19, 2015 I did something very stupid. When I raise the flag that the game is over, I simply bail out of the function without calling the render for that last time. By putting on the top every function call, it is always called before I bail out of the function. Here is how I did it:MainGameScene.prototype.update = function(){ this.mRenderer.render(this.mStage);if(this.mIsGameOver)return;...}Before, I call render before the function ends. That's the reason why it only shows the last frame drawn, as xerver mention. Now I call it before the function updates. I haven't cleaned the code yet but I will follow-up the improvements later on. Thank you! 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.