我想知道我应该用什么代替
animationWithFrames:delay:
和
actionWithAnimation:restoreOriginalFrame:
因为他们发出警告称他们已被弃用。
答案 0 :(得分:12)
Cocos2d 2.0使用
CCAnimation
+(id) animationWithSpriteFrames:(NSArray*)frames delay:(float)delay
CCAnimate
+(id) actionWithAnimation: (CCAnimation*)anim
文档:
http://www.cocos2d-iphone.org/api-ref/2.0.0/interface_c_c_animation.html
http://www.cocos2d-iphone.org/api-ref/2.0.0/interface_c_c_animate.html
答案 1 :(得分:11)
您需要做的唯一更改是使用新属性:restoreOriginalFrame。
从构造函数中删除restoreOriginalFrame,然后在新行中设置属性:
animation.restoreOriginalFrame = NO;
就是这样!
答案 2 :(得分:0)
CCAnimation *sampleAnim = [CCAnimation animationWithAnimationFrames:
sampleAnimFrames delayPerUnit:0.2f loops:7];
答案 3 :(得分:0)
我在使用的项目中遇到同样的问题。
CCSprite *image = [CCSprite spriteWithSpriteFrameName:@"a0001.png"];
image.position = ccp(s.width/2,s.height/2);
[self addChild:image];
image.tag = 1;
NSMutableArray *frames = [[NSMutableArray alloc] init];
for (int i = 1; i <= 10; i++) {
NSString *frameName = [NSString stringWithFormat:@"a%04i.png",i];
[frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
CCAnimation *ani = [CCAnimation animationWithSpriteFrames:frames delay:1.0f/8.0f];
[image runAction:[CCAnimate actionWithAnimation:ani]];
这对我来说很好。