PaulR Posted July 6, 2013 Share Posted July 6, 2013 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 thiswhile(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? ThanksPaul Quote Link to comment Share on other sites More sharing options...
xerver Posted July 6, 2013 Share Posted July 6, 2013 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 RussiSunni 1 Quote Link to comment Share on other sites More sharing options...
enpu Posted July 7, 2013 Share Posted July 7, 2013 I use this to remove all from stage: for (var i = stage.children.length - 1; i >= 0; i--) { stage.removeChild(stage.children[i]);}; Quote Link to comment Share on other sites More sharing options...
PaulR Posted July 7, 2013 Author Share Posted July 7, 2013 Thanks and I had not thought of using a container to hold all the objects for each screen (scene), I kind of like that solution. I will try out that idea tonight. Thanks again.. 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.