2013-03-13 40 views
1

我想在我的项目中使用以下几行代码。使用setDelay和addFrameWithFilename时的警告

// 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

看看CCAnimation.h文件。 '/ **“延迟单位”的延迟秒数*/ @property(nonatomic,readwrite)float delayPerUnit;' – Kreiri 2013-03-13 19:35:24

回答

1

嗯...不确定这些方法是否存在。这里是我的代码库(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;