我想知道我应该在的地方,因为他们给予警告,他们已经被弃用使用的Cocos2D - animationwithframes:延迟:弃用
animationWithFrames:delay:
和
actionWithAnimation:restoreOriginalFrame:
。
我想知道我应该在的地方,因为他们给予警告,他们已经被弃用使用的Cocos2D - animationwithframes:延迟:弃用
animationWithFrames:delay:
和
actionWithAnimation:restoreOriginalFrame:
。
的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
好的答案,但它遗漏了OP后半部分问题的一个细节。具体而言,您还必须将动画的“restoreOriginalFrame”属性设置为与以前在弃用版本中指定的内容相匹配。请参阅下面的Julio的答案。 (顺便说一下,doc链接不再有效。) – Dalmazio
您需要做的唯一更改是使用新属性:restoreOriginalFrame。从构造
删除restoreOriginalFrame,那么,在新线,设置属性:
animation.restoreOriginalFrame = NO;
这就是它!
这是OP问题后半部分的正确答案。设置动画的“restoreOriginalFrame”属性以匹配之前指定的内容是被接受的答案未被忽略的重要细节。 – Dalmazio
CCAnimation *sampleAnim = [CCAnimation animationWithAnimationFrames:
sampleAnimFrames delayPerUnit:0.2f loops:7];
我在我使用的项目中遇到同样的问题。
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]];
这对我很好。
检查CCDeprecated.h和.m文件,了解应如何编写废弃的代码 – LearnCocos2D