2013-02-01 205 views
0

按照建議對我的代碼進行調整後,我的動畫現在可以運行。現在,我想問一下如何扭轉精靈的動作。我正試圖讓這個精靈像風中吹來一樣移動。這裏是我的代碼現在:扭轉精靈動畫

-(id) init 
{ 
// always call "super" init 
// Apple recommends to re-assign "self" with the "super's" return value 
if((self=[super init])) { 
    CGSize winSize = [[CCDirector sharedDirector] winSize]; 
    self.isTouchEnabled = YES; 

    CCSprite *black = [CCSprite spriteWithFile:@"b.png"]; 
    black.position = ccp(100, 160); 
    black.scaleX = 100/black.contentSize.width; 
    black.anchorPoint = ccp(0.03, 0); 

    CCSpriteFrameCache *frame = [CCSpriteFrameCache sharedSpriteFrameCache]; 
    [frame addSpriteFramesWithFile:@"bLongAnimation.plist"]; 
    CCSpriteBatchNode *bHair = [CCSpriteBatchNode batchNodeWithFile:@"bLongAnimation.png"]; 
    [self addChild:bHair]; 

    [self addChild:black z:1 tag:1]; 

    //Animation 
    NSMutableArray *animateBlackHair = [NSMutableArray arrayWithCapacity:10]; 
    for (int i = 1; i < 10; i++) 
    { 
     NSString *animBlackHair = [NSString stringWithFormat:@"b%i.png", i]; 
     CCSpriteFrame *blackFrame = [frame spriteFrameByName:animBlackHair]; 
     [animateBlackHair addObject:blackFrame]; 

     //I added this code block thinking it might work 
     for(i = 10; i > 1; i--) 
     { 
      NSString *revAnimation = [NSString stringWithFormat:@"bRightLong%i.png", i]; 
      CCSpriteFrame *revFrame = [frame spriteFrameByName:revAnimation]; 
      [animateBlackHair1 addObject:revFrame]; 
     } 
    } 
    CCAnimation *blowHair = [CCAnimation animationWithSpriteFrames:animateBlackHair delay:0.1]; 
    CCAction *blowingHair = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:blowHair]]; 
    [black runAction:blowingHair];   
} 
return self;} 

我的猜測沒有工作,所以我不知道我怎樣才能儘快扭轉運動,因爲它完成的第一個?

更新:沒關係,我想通了。我只是移動了for循環以反轉另一個循環之外的動作。感謝您的幫助。

+1

我不確定這是否是問題,但延遲爲0可能會使您的動畫運行得太快,以至於看不到它,請嘗試將其設置爲0.1或0.4。 – bluestunt

+0

奇怪的是,這確實是問題。我試圖將它設置爲0,因爲我有一個計時器,該計時器只能在該場景中運行5秒鐘。謝謝。 – user1597438

回答

2

嘗試將動畫上的延遲設置爲0以外的值。嘗試0.1或0.4或其他值。如果將其設置爲零,我不認爲動畫運行,如果它運行,則運行速度太快而不可見。