我想在我的项目中使用以下几行代码。
// 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是否已被弃用?如果是,我应该用什么来代替他们。请帮帮忙。
发布于 2013-03-14 02:31:19
嗯..。根本不确定这些方法是否存在。下面是我的代码库(cocos2 2.0版)中的一个示例。
+ (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,则延迟的设置器为
animation.delayPerUnit = 0.6f;https://stackoverflow.com/questions/15393373
复制相似问题