By using SimpleAudioEngine
, we can play background music very easily. SimpleAudioEngine
is a shared singleton object that can be called from anywhere in your code. In SimpleAudioEngine
, we can play only one background score.
We have to include the header file of SimpleAudioEngine
to use it. Therefore, you will need to add the following code:
#include "SimpleAudioEngine.h"
The following code is used to play background music called background.mp3
.
auto audio = CocosDenshion::SimpleAudioEngine::getInstance(); audio->preloadBackgroundMusic("background.mp3"); // play the background music and continuously play it. audio->playBackgroundMusic("background.mp3", true);