I’m trying to create an animated sprite from a sprite sheet, to do this I’m running the following:
NSMutableArray *bunsenAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 74; ++i) {
[bunsenAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"15_%i.png", i]]];
}
for (int j = 1; j <= 74; ++j) {
[bunsenAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"15_1.png"]]];
}
for (int k = 75; k <= 148; ++k) {
[bunsenAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"15_%i.png",k]]];
}
for (int l = 1; l <= 74; ++l) {
[bunsenAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"15_1.png"]]];
}
NSLog(@"bunsenAnimFrames is %@", bunsenAnimFrames );
CCAnimation *bunsenAnimationAnimation = [CCAnimation animationWithSpriteFrames:bunsenAnimFrames delay:1/25];
bunsens = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:bunsenAnimationAnimation]];
Then later during populating a stage with a set of tiled sprites I run:
else if (blockValue == 2 || blockValue == 3 || blockValue == 4 || blockValue == 5) {
bunsen = [CCSprite spriteWithSpriteFrameName:@"15_1.png"];
if (blockValue == 2) {
bunsen.rotation = 90;
}
else if (blockValue == 3) {
bunsen.rotation = 180;
}
else if (blockValue == 4) {
bunsen.rotation = 270;
}
float tileY = screenSize.height-((countery*startData4)+startData4/2+77.5)/2;
float tileX = ((counterx*startData4)+startData4/2+5)/2;
bunsen.position = ccp(tileX,tileY);
[bunsenAnimation addChild:bunsen];
[bunsen runAction:bunsens];
}
This works perfectly well in adding the bunsen sprite (declared as a sprite in header file) however on calling [bunsen runAction:bunsens]; nothing happens to the sprite, any reason for this?
The solutions I found for this was not using a fraction in the delay for CCAnimation… strange! as I thought the delay value could be any float!