Efficiently spawning sprites in Cocos2D
Just a quick question here; I have a background image in my game. Every time I spawn an sprite, I use the [self addChild:@""]; statement. Would it be more efficient to to cal开发者_JAVA技巧l [backgroundImage addChild:@""]; instead? I have tested both ways and they both work, but I cannot tell which is more efficient, or if it even makes a difference.
Thanks,
Tate
If your object is CCLayer, calling [self addChild:img], the image will be added to the CCLayer.
I believe your background image is a CCSprite. [background addChild:img], will add the sprite to the background. If you adjust your background, like moving it up, all the sprites attached to background(child of background) would be moving together with the background image.
When you called [self removeChild:background], all the child attached to the background would be removed as well..
It depends on what are the requirements of the game.. =)
精彩评论