2011-03-15 65 views
1

我在sprite.I創建動畫我改變perticular週期之後精靈和重複它精靈動畫forever.I已經提到許多位點和格式是相同的,如下:沒有顯示在cocos2d

-(id) init 
{ 
    if((self=[super init])) 
    { 

     CCSpriteSheet *spriteSheet = [CCSpriteSheet spriteSheetWithFile:@"apls.png" capacity:3]; 

     [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"apls.plist"]; 

     CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"apple2.png"]; 
     sprite.position = ccp(230,230);      
     [spriteSheet addChild:sprite]; 
     [self addChild:spriteSheet]; 


     NSMutableArray *animFrames = [NSMutableArray array]; 
     for(int i = 2; i < 5; i++) 
     { 

      CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] 
         spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]]; 
      [animFrames addObject:frame]; 

     } 

     CCAnimation *animation = [CCAnimation animationWithName:@"dance"  
           delay:0.2f frames:animFrames]; 

     [sprite runAction:[CCRepeatForever actionWithAction: 
     [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]]; 

    } 
    return self; 
} 

這是代碼相同。但在模擬器上它沒有顯示任何東西。只是幀率不斷變化。
有什麼我失蹤?

在此先感謝。

+0

是你的精靈顯示,如果你評論的所有動畫代碼? – Andrew 2011-03-15 12:14:46

+0

是的,沒有動畫它顯示其他精靈CCSprite * p = [CCSprite spriteWithFile:@「apple1.png」]; \t \t \t p.position = ccp(230,230); \t \t \t [self addChild:p z:0 tag:1];此代碼顯示apple1圖像,但動畫代碼不起作用。 – user392406 2011-03-15 12:21:48

+0

有cocos2d附帶的框架動畫示例(在spriteTest示例中)。看看那裏 – Andrew 2011-03-15 12:29:05

回答

1

試試這個。

NSMutableArray *animFrames = [NSMutableArray array]; 
    for(int i = 2; i < 5; i++) 
    { 

     CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] 
        spriteFrameByName: [NSString stringWithFormat:@"apple%d.png",i]]; 
     [animFrames addObject:frame]; 
    } 

CCAnimation *animation = [CCAnimation frames:animFrames delay:0.2f]; 

[sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO] ]];