Jump to content

DisplayObjectContainer.RemoveAll Bugfix


sima
 Share

Recommended Posts

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#l177

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

Link to comment
Share on other sites

or

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

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