Jump to content

how to remove sprite from render list?


ye0jun
 Share

Recommended Posts

I made virtual camera with container

and I want show sprites only in this camera's range

so I use 'removeChild' for out of camera's range sprites and again 'addChild' when they in camera.

but 'removeChild' is very slow...

then how to do it?? 

Link to comment
Share on other sites

If you can group the sprites into containers, one per area for instance, you can reduce the amount of add/remove calls that way.

Also, have you tried setting sprite.visible to true/false instead of adding/removing from stage?

Link to comment
Share on other sites

If you want to avoid updating and drawing sprites that go off-camera, setting the sprite's visibility can achieve this. There's still some extra processing to loop through and call render and check this.visible for each sprite, but the invisible sprites' transforms aren't updated and they aren't drawn either. So this can sometimes perform better than adding to and removing from the stage, for instance if the sprites are going on and off camera quickly and repeatedly, back and forth. On the other hand, sometimes adding to and removing from the stage can perform better, for instance if the sprites are moving on and off camera infrequently.

You can also try combining both methods, for example when the sprite first goes off camera set sprite.visible to false. Then if it comes back into the camera's view soon, just set sprite.visible back to true. But if it stays off camera too long, then remove it from the stage.

And grouping the sprites into containers can sometimes boost performance too. For instance, if several sprites always move on and off camera at about the same time, then you can reduce the amount of add/remove processing by adding/removing the whole container at once, instead of performing a separate add/remove for each sprite. And if a container is invisible, then its children aren't processed, so grouping can reduce the amount of invisible elements that need to be processed/checked.

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