2013-10-07 20 views
0

如何我會同步與動畫(CCAnimation)音效通訊錄與內部CCAnimation幀進行了cocos2d 2.x的聲音*

 NSMutableArray* animationframes = [NSMutableArray array]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime01.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime02.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime03.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime04.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime05.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     [animationframes addObject:[[[CCAnimationFrame alloc] initWithSpriteFrame:[TitleLayer spriteframeForFile:@"title_startanime06.png"] delayUnits:1 userInfo:nil] autorelease]]; 
     CCAnimation* animation = [CCAnimation animationWithAnimationFrames:animationframes delayPerUnit:0.09 loops:1]; 

我可以以某種方式加入callblock到animationframes陣列?

或者它可以工作,如果CCAnimationFrame有一個可選的回調/委託,當它被激活。

+0

現在我發現這一點:http://www.cocos2d-iphone.org/forums/topic/usage-of-ccanimationframedisplayednotification/#post- 409613將嘗試。根據文檔 – Jonny

回答

0

好了所有我們需要做的是:

  1. 遵守通知CCAnimationFrameDisplayedNotification。 它在動畫的精靈上被調用。

  2. 爲了廣播 通知,需要將字典添加到您要鉤入的CCSpriteFrame中,並將 添加到該字典中。我添加了一個NSDictionary ,其中包含所有精靈圖 的每個精靈的精靈幀名稱,因爲我需要鉤住它們,但我猜字典 也是空的,而不是nil

    animationframe = [[[CCAnimationFrame alloc] initWithSpriteFrame:[cache spriteFrameByName:str] delayUnits:1 userInfo:nil] autorelease]; 
        animationframe.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:str, @"spriteframename", nil]; 
        [animationframes addObject:animationframe]; 
    
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frameupdatedinbootanimation:) name:CCAnimationFrameDisplayedNotification object:NULL]; 
    

然後抓住它

-(void)frameupdatedinbootanimation:(id)hmm { 
    NSLog(@"frameupdatedinbootanimation: %@", hmm); 
    Do something here 
+0

。 ymmv:我嘗試了一些關於遊戲玩法的重要方面(例如,在攻擊者動畫幀9上同步一個fx)。特別是在模擬器中,FPS是一個隨機數,通常不會發布通知。我推斷這是因爲幀實際上被跳過了......所以我最終離開了它。 – YvesLeBorg

+0

有一個文檔(除了源註釋)?無論如何,我也使用這種方法來調整精靈位置,因爲我的設計師給我發送了每幀不同的原點。咄。所以我最終在那裏製作了一個小API(dic中的pos鍵意味着原點改變),因爲每個通知只能有一個處理程序。讓我希望有一天有人會將此烘焙到CCAction流程中。 – Jonny

+0

大聲笑,這只是一個關於文檔的'sn''。 Notin,nada,null,rien!無論如何,如果你所做的只是調整每一幀的內容(位置,透明度等等),而且需要做的事情的本質是在字典(ergo api)中,它就會適用於你。如果你需要做一些關鍵的遊戲(就像我一樣),避免這種情況。 – YvesLeBorg