sima Posted April 8, 2014 Share Posted April 8, 2014 The function DisplayObjectContainer.RemoveAll is marked as "NOT tested yet" and the source code is commented out.Link: http://www.goodboydigital.com/pixijs/docs/files/src_pixi_display_DisplayObjectContainer.js.html#l177PIXI.DisplayObjectContainer.prototype.removeAll = function(){ for(var i = 0 , j = this.children.length; i < j; i++) { this.removeChild(this.children[i]); }};The array is iterated first-to-last and at the same time the children are removed. This leads to an "out of bounds"-error. If you iterate the array last-to-first and remove the children, the function works correctly: PIXI.DisplayObjectContainer.prototype.removeAll = function(){ for(var i = (this.children.length-1); i >= 0; --i) { this.removeChild(this.children[i]); }};I started working with Pixi a week ago and as far as I can tell, this library is very useful. Cheers,Sima Quote Link to comment Share on other sites More sharing options...
xnamex Posted April 8, 2014 Share Posted April 8, 2014 orPIXI.DisplayObjectContainer.prototype.removeAll = function() { while (this.children[0]) { this.removeChild(this.children[0]); }};Honestly, I'm not sure, but either of them are not bringing a lot of performance improvement. I have games deployed with with all 3 forms of removing all, and I can't seem to find that point, where I can say with confidence that "Yes no.X is definitely the way to go!". The only thing I can see here, is that you won't need to declare another variable, like i. It's a matter of taste. Cheers! Quote Link to comment Share on other sites More sharing options...
xerver Posted April 8, 2014 Share Posted April 8, 2014 This was implemented in the development branch as `removeChildren`: https://github.com/GoodBoyDigital/pixi.js/blob/dev/src/pixi/display/DisplayObjectContainer.js#L188 xnamex 1 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.