//初始化声音
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic( std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str() );
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str(),true);
//控制开关
//打开
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathForFilename("background.mp3")).c_str(),true);
//关闭
SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
原文链接:https://www.f2er.com/cocos2dx/343575.html