Tuesday, October 22, 2013

Cocos2D Sprite Sheets: To Use CCSpriteBatchNode Or Not

Examples such as the one here use CCSpriteBatchNode as it is apparently some form of "best practice" to do so due to apparent performance benefits by batching draw operations.

However, the benefits of doing this is debatable, with the following articles claiming only marginal benefits in most use cases, and with significant benefits only in certain situations:

Obviously if using CCSpriteBatchNode is easy then it's a no brainer to use it. But unfortunately it gets pretty complicated when you have a sprite that requires multiple sprite sheets. Rather than to have to figure out how it all has to work, or if it can even work in the first place, it's a pretty straightforward decision instead to not use it.

So from the sprite sheet tutorial, instead of using CCSpriteBatchNode:
  1. Load all the various sprite sheets into the sharedSpriteFrameCache
  2. Create one CCAction for every animation sequence using the frame names
  3. Create a Sprite directly using 1 of the frames
  4. Call runAction on the sprite whenever a new animation sequence needs to be run
Other References:

No comments:

Post a Comment