spritesheets and cocos2d

Nibbie
Posts: 2
Joined: 2012.03
Post: #1
how can i use animation and spritesheets in cocos2d programming ?
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
Code:
[[CCspriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spritesheetfile.plist"]

CCanimation* anim = [CCAnimation animation];
anim.delay = .1;
for(int x = 0; x< 5; x++)
{
   [anim addFrame:[[CCspriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"mything%d.png",x]];
}
CCSprite* sprite = [CCSprite spriteWithFrame:[[CCspriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"mything0.png"]];
[sprite runAction: [CCAnimate actionWithAnimation:anim]];
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2012.03
Post: #3
thanks for sharing the information here.. Could you tell me what are the benefits of sprite sheets over openGL ES custom coding in cocos2d ?
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #4
nope
Quote this message in a reply
Apprentice
Posts: 7
Joined: 2012.09
Post: #5
(Mar 9, 2012 01:31 AM)nitin867 Wrote:  thanks for sharing the information here.. Could you tell me what are the benefits of sprite sheets over openGL ES custom coding in cocos2d ?

For us it was ease of use. We know how to just use sprite sheets so that is what we followed. All we had to do was use something like Texture Packer to make our sprite sheet and then with a couple lines of code we could access it and get all our sprites out for our game.
Quote this message in a reply
Post Reply