Reputation: 629
I am using following code for sprite animation in cocos2d
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"AnimBear.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"AnimBear.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"bear%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.1f];
CGSize winSize = [CCDirector sharedDirector].winSize;
self.bear = [CCSprite spriteWithSpriteFrameName:@"bear1.png"];
_bear.position = ccp(winSize.width/2, winSize.height/2);
self.walkAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[_bear runAction:_walkAction];
[spriteSheet addChild:_bear];
I need not getting clear idea about CCSpriteBatchNode why this is used here?
Upvotes: 1
Views: 386
Reputation: 1041
You do not need to use the CCSpriteBatchNode for a single animation.
The CCSpriteBatchNode is used when you want to display many objects taken from the same sprite sheet. In this case rendering the stuff is much faster than rendering individual sprites. As long as you use a single sprite there is no speed up since the sprites in an animation are displayed in separate frames.
Upvotes: 3