これは可能です。
一般的な解決策
float duration = 10.0f;
CCSequence *soundSequence = CCSequence::create(CCDelayTime::create(duration),CCCallFunc::create(this, callfunc_selector(GamePlay::soundEndedAction)),NULL);
this->runAction(soundSequence);
サウンドエンドアクションを監視する方法
void GamePlay::soundEndedAction(){
CCLOG("+++sound ended+++%s",__PRETTY_FUNCTION__);
}
//======== 以下のソリューションを適用できるのは iOS プラットフォームのみです。=====//
「AppController.h」にメソッドを作成しました
-(void)backgroundFinished;
そして「AppController.mm」
-(void)backgroundFinished
{
NSLog(@"+++Music ended....+++");
CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
}
「SimpleAudioEngine_objc.m」ファイルのinitメソッドに以下の行を追加
-(id) init
{
if((self=[super init])) {
am = [CDAudioManager sharedManager];
//=======added this line=========//
[am setBackgroundMusicCompletionListener:[[UIApplication sharedApplication]delegate] selector:@selector(backgroundFinished)];//28 Aug 2014
//===============================//
soundEngine = am.soundEngine;
bufferManager = [[CDBufferManager alloc] initWithEngine:soundEngine];
mute_ = NO;
enabled_ = YES;
}
return self;
}
「GamePlay.cpp」クラスで、更新メソッドをスケジュールしました
void GamePlay::update(float dt)
{
if(!CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
{
CCLOG("+++Background Music Ended+++ :%d",CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying());
//Take neccessory actions
}
}