如何将声音效果与动画同步(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];
我可以以某种方式向animationframes数组添加一个callblock吗?
如果CCAnimationFrame在激活时有一个可选的回调/委托,它可以工作。
答案 0 :(得分:0)
好的,我们所要做的就是:
观察通知CCAnimationFrameDisplayedNotification。 它被调用了动画的精灵。
为了
要播放的通知,需要添加字典
到你要挂钩的CCSpriteFrame。我添加了一个NSDictionary
包含所有spriteframe的每个sprite的spriteframename
因为我需要挂钩所有这些,但我想字典可以
也是空的,不是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