I am developing a game for iOS and Android using Cocos2d-X 3.10 and I am having trouble chaning the effects volume using the Simple Audio Engine.
I’ve seen the documentation and the function that I am calling is: audioEngine->setEffectsVolume(volume);., however when I do this, nothing happens (note: I am testing my program on Windows using Visual Studio).
What is stranger is that when I went into the setEffectsVolume function, I found out that it has no implementation. From SimpleAudioEngine.cpp:
If you still need volume control on Windows, try new AudioEngine. It’s a little bit different, but still simple enough to use even by beginners. In cocos2d-x v3.10 it doesn’t support wav on Windows (again: works on Android), but works great with mp3 and ogg.
Header file is called AudioEngine.h, and it uses namespace “cocos2d::experimental” (it took me a while to find this detail).
There is no difference in background music and effects, so you have to store IDs returned by AudioEngine::play2d() function, or you can set the volume by calling play2d() with proper value. Example: experimental::AudioEngine::play2d(“sound.mp3”, false, 0.5f) plays sound.mp3, without looping (false), with volume set to 50% (0.5f).
Or you can use setVolume() after calling play2d(), with sound ID and the volume level. Example:
int id = experimental::AudioEngine::play2d(“sound.mp3”);
experimental::AudioEngine::setVolume(id, 0.5f);
And you can add “using namespace cocos2d::experimental;” to avoid typing “experimental” every time