not showing sprite animation in cocos2d
I am creating animation in sprite.I am changing sprite after perticular period and repeating it forever.I have referred many site and the format is same as below:
-(id) init
{
if( (self=[super init] ))
{
CCSpriteSheet *spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"apls.png" capacity:3];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"apls.plist"];
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"apple2.png"];
sprite.position = ccp(230,230);
[spriteSheet addChild:sprite];
[self addChild:spriteSheet];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 2; i < 5; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]];
[animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithName:@"dance"
delay:0.2f frames:animFrames];
[sprite runAction:[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];
}
return self;
}
this is the code for the same. But on simulator it is not showing anything. just frame rate keeps on changing.
Is there something开发者_StackOverflow which I am missing?thanks in advance.
Try this.
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 2; i < 5; i++)
{
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache]
spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]];
[animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation frames:animFrames delay:0.2f];
[sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];
精彩评论