Search code examples
c++cocos2d-x

Playing sounds in sequence with CocosDenshion?


I am developing a simple videogame using Cocos2d-x library and Cocosdenshion AudioEngine.

I can play single sounds using SharedAudioEngine's playEffect method, but what I am trying to do is to play a number of sounds in a sequential ordeq.

But I have no idea where to start. I've tried to create an action sequence, which would call the method using selectors, but it doesn't seem to work.


Solution

  •     write number of Function equal to the Number of Sound effects.
        like this
        Function1(){
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sound1.mp3");
        }
        Function2{
        CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sound2.mp3");
        }
        Function3{
        CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
            CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("Sound3.mp3");
        }
    CCSequence *seq = CCSequence::create(Func1,func2,func3,NULL);
    CCRepeatForever *repeat = CCRepeatForever::create(seq);
    this->runAction(repeat);