Jump to content

How to 'remove' all children added to Container?


neonwarge04
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...