0

私の目標は、cocos2dx で BGM が終了した後に関数を呼び出すことです。

このコードを使用してバックグラウンド ミュージックを再生する

    CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("shortSound.wav",false);

私の関数を呼び出す必要があります

void GamePlay::gameLevelEnds()

バックグラウンドサウンドが終了したとき。

4

2 に答える 2

0

これは可能です。

一般的な解決策

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
    }
}
于 2014-08-28T09:21:38.557 に答える