本文介绍了同步里面CCAnimation帧进行了cocos2d 2.x的声音*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将同步与动画(CCAnimation)
How would I sync sound effects with an animation (CCAnimation)
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阵列?
Can I add a callblock somehow to the animationframes array?
或者,如果CCAnimationFrame有当它激活一个可选的回调/委托它可以工作。
Or it could work if a CCAnimationFrame had a optional callback/delegate for when it's activated.
推荐答案
好吧,我们所要做的是:
Ok all we have to do is:
-
观察通知CCAnimationFrameDisplayedNotification。
这就是所谓的上是动画精灵。
Observe the notification CCAnimationFrameDisplayedNotification.It's called on the sprite that is animated.
为了使
通知要被广播,字典将需要添加
到要挂接到CCSpriteFrame。我添加了一个的NSDictionary
包含每个精灵的spriteframename所有spriteframes
因为我需要挂钩所有的人,但我猜可能词典
为空好,只是没有无
。
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
这篇关于同步里面CCAnimation帧进行了cocos2d 2.x的声音*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!