开发者

The best way to remove a sprite from a batch in Cocos2D

I'm using Cocos2D in my project and I'm quite new to this library. And I don't understand one thing.

I have many sprites on the scene which are added and removed constantly. So at certain moment a sprite becomes useless and I have to remove it fo开发者_JAVA百科rm a batch node.

In the comments of the removeChild method of CCSpriteBatchNode class is said:

 @warning Removing a child from a CCSpriteBatchNode is very slow

Does anybody know what the best method of removing a sprite?

Thanks!


Instead of adding and removing sprites why not re use them, then you won't have any slow down caused by adding or removing sprites.

Setting a sprite not to be visible saves the render cost and when you need to add it again just move it to position and the texture frame if you need to and then turn the visibility back on.

I subclass a ccSprite and then add them to an array to keep track of active and inactive sprites.

Dave.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜