我想在我的项目中使用以下代码行。
// Create the intro image
CGSize screenSize = [CCDirector sharedDirector].winSize;
CCSprite *introImage = [CCSprite spriteWithFile:@"intro1.png"];
[introImage setPosition:ccp(screenSize.width/2, screenSize.height/2)];
[self addChild:introImage];
// Create the intro animation, and load it from intro1 to intro7.png
CCAnimation *introAnimation = [CCAnimation animation];
[introAnimation setDelay:2.5f];
for (int frameNumber=0; frameNumber < 8; frameNumber++) {
CCLOG(@"Adding image intro%d.png to the introAnimation.",frameNumber);
[introAnimation addFrameWithFilename:
[NSString stringWithFormat:@"intro%d.png",frameNumber]];
我收到警告:
instance method '-setDelay:' not found (return type defaults to 'id')
指向
行[introAnimation setDelay:2.5f];
以及指向该行的类似警告
[introAnimation addFrameWithFilename: [NSString stringWithFormat:@"intro%d.png",frameNumber]];
是否已弃用setDelay和addFrameWithFilename?如果是的话,我应该在他们的位置使用什么。请帮忙。
答案 0 :(得分:1)
+ (CCAnimation *) getAnimationForSoldier:(Soldier *)theSoldier animationType:(mapAnimationTypeE)animationType {
id animation = nil;
NSString *animationName = [SpriteUtils getAnimationNameForSoldier:theSoldier animationType:animationType];
if (!animationName) return nil;
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist", animationName]];
if ((animation = [[CCAnimationCache sharedAnimationCache] animationByName:animationName])) {
return animation;
} else {
NSUInteger numberOfFrames = 8;
if (animationType == mapAnimationTypeCast || animationType == mapAnimationTypeSkill) numberOfFrames = 20;
NSMutableArray *frames = [NSMutableArray arrayWithCapacity:numberOfFrames];
for (NSUInteger i = 1 ; i <= numberOfFrames ; i++) {
NSString *frName = [SpriteUtils getFrameNameForAnimationNamed:animationName andFrame:i];
CCSpriteFrame *frr = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frName];
if (frr) {
[frames addObject:frr];
} else {
MPLOGERROR(@"*** No frame named [%@], bailing out.", frName);
return nil;
}
[frames addObject:frr];
}
animation = [CCAnimation animationWithSpriteFrames:frames delay:.06];
[[CCAnimationCache sharedAnimationCache] addAnimation:animation name:animationName];
}
return animation;
}
注意:首先创建您的spriteframes数组,然后使用数组和所需的延迟创建动画。
延迟是每帧之间的延迟(不是总持续时间)。
如果您使用的是cocos2d版本2.N,延迟的setter是
animation.delayPerUnit = 0.6f;