Jump to content

Remove all children from a Stage


PaulR
 Share

Recommended Posts

Hi,
 
I am currently attempting to learn to use Pixi.js and in my learning demo have set up a number of screens (Title, LevelSelect and InGame) and they all share a single Stage. I have been trying to find an easy way to remove all the Sprites from the stage when I swap between screens.
 
I have ended up with this
while(this.stage.children.length > 0){   var child = this.stage.getChildAt(0);  this.stage.removeChild(child);}

inside my changeScreen method.

 

Have I missed a remove all children method or is it that I am miss using Pixi.js. Is it usual to share a single stage between screens or do people manage multiple stages, one for each screen?
 
Thanks
Paul
 
Link to comment
Share on other sites

Instead of removing sprites just show/hide some DisplayObjectContainers that each represent your scenes:

 

var scene1 = new PIXI.DisplayObjectContainer(),    scene2 = new PIXI.DisplayObjectContainer(),    scene3 = new PIXI.DisplayObjectContainer();//add some stuff to scene 1scene1.addChild(new PIXI.Sprite(myTexture));//add some stuff to scene 2scene2.addChild(new PIXI.Sprite(anotherTexture));//add some stuff to scene 3scene3.addChild(new PIXI.Sprite(moarTexture));//add all the scenes to the stagestage.addChild(scene1);stage.addChild(scene2);stage.addChild(scene3);//show only scene1scene2.visible = false;scene3.visible = false;

Then you can use `visible` to show h ide  whichever scenes you want

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...