尝试通过循环运行动画,构建成功但无法在模拟器上执行动画,下面是应该执行动画的代码
NSMutableArray *frames = [[NSMutableArray alloc]init];
//supposed to loop through file names a0001 to a0010 from texture file.
for (int i=1; i<=10; i++) {
NSString *frameName = [NSString stringWithFormat:@"a%04i.png",i];
[frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
// set the frame speed
CCAnimation *a =[CCAnimation animationWithSpriteFrames:frames delay:1.0f/24.0f];
// supposed to use restoreoriginalframe method after actionwithanimation but since it is deprecated removed it
[mole runAction:[CCAnimate actionWithAnimation:a]];
非常感谢任何帮助,谢谢
答案 0 :(得分:0)
这就是我如何完成同样的事情。如果不将我的图像加载到数组中,我可以看到唯一的区别,但是这些是使用精灵表加载到内存中的纹理。
NSString * animateCycle = [NSString stringWithFormat:@"ImageName 00%%02d.png"];
图像名称将沿着&#34; ImageName 0001.png&#34;,&#34; ImageName 0002.png&#34;等等。
CCActionInterval * action = [CCAnimate actionWithSpriteSequence:animateCycle numFrames:8 delay:.1 restoreOriginalFrame:YES];
[mySprite runAction:action];
这将根据指定的延迟循环显示图像。
我希望这会有所帮助。