Delay to play music game

I want to create a delay time before I play a music. I try use CCSequence but it fail :frowning:

        CCDelayTime* delayAction = CCDelayTime::create(2.0f);

        CCCallFunc* callPlayAudio = CCCallFunc::create( this, callfunc_selector(CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(namePrefix.c_str())));
        this->runAction( CCSequence::create( delayAction, callPlayAudio, NULL ) );

Here is notifi from LogCat: “lvalue required as unary ‘&’ operand”
Someone can help me fix it, please :frowning:

CCDelayTime* delayAction = CCDelayTime::create(5.0f);
CCCallFuncO* callPlayAudio = CCCallFuncO::create( this , callfuncO_selector( GG_Scene::gg_playAudio ) , CCString::create(“audio_file_name” ) ) ;
this->runAction( CCSequence::create( delayAction, callPlayAudio, NULL ) );

//-----------------------------------------------------------------//

void GG_Scene::gg_playAudio( CCObject obj )
{
CCLOG( “WE WILL PLAY THIS AUDIO FILE: %s”, ((CCString
)(obj))->getCString() );
}

Hello Hoangtaiki,
CCCallFunc only supports methods like void my_call(void).
To do the thing you want, use the code below (I suppose your scene’s name is MyScene):

// in MyScene::init()
CCDelayTime *delayAction = CCDelayTime::create(2.0f);
CCCallFunc *callFunc = CCCallFunc::create(this, callfunc_selector(MyScene::playMusic));
this->runAction(CCSequence::create(delayAction, callFunc, NULL));

// in MyScene.cpp
void MyScene::playMusic()
{
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(namePrefix.c_str());
}

PS. if you’re using cocos2d-x v3 or higher, it’s better to remove ‘CC’ prefixes, like
DelayTime* delayAction = DelayTime::create(2.0f);.