Ashley Staggs
Ashley Staggs

Reputation: 1567

Cocos2d SpriteSheet Animation

everywhere i look i find code on how to run an animation using file created from zwoptex, but it is using deprecated code. I can't find code on how to run the animation using CCSpriteBatchNode.

Any suggestions?

Upvotes: 2

Views: 1299

Answers (1)

sergio
sergio

Reputation: 69047

This is the way I do animations using files created from zwoptex, but I am using CCSpriteFrameCache. I don't get any warnings, so I suppose this code is not deprecated:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"frameSheet.plist"];
NSMutableArray* frames = [NSMutableArray array];
for(int i = 1; i <= numberOfFrames; ++i) {
    [frames addObject:
     [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"frame-%03d.png", i]]];
}
CCAnimation* anim = [CCAnimation animationWithFrames:frames delay:0.3f];

Texture file is named frameSheet.png, plist file is frameSheet.plist, and the composing images are named frame-001.png ... frame-100.png.

Let me know if this helps you.

EDIT:

strangely, for me animationWithFrames:frames is not deprecated:

enter image description here,

it says "from 0.99.5" and I have no issues with my animations...

Upvotes: 3

Related Questions