Jennifer
Jennifer

Reputation: 1852

Unable to hear the sound effect in cocos2dx

I have the following code and the problem is that the battle.mp3 music plays normally however, the bang.mp3 sound effect does not play. Any ideas?

bool GameLayer::init(int level)
{
    if (!Layer::init())
        return false;

SimpleAudioEngine::sharedEngine()->playBackgroundMusic("battle.mp3", true);
SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.5);
SimpleAudioEngine::sharedEngine()->preloadEffect("bang.mp3");

I tried to play the following sound effect when the enemy character is damaged, but unable to hear any sound.

int soundID = SimpleAudioEngine::sharedEngine()->playEffect("bang.mp3");

Upvotes: 0

Views: 396

Answers (1)

AAryan
AAryan

Reputation: 20140

Use SimpleAudioEngine::getInstance() instead of SimpleAudioEngine::sharedEngine() because sharedEngine() is deprecated now.

For Sound Effects, .mp3 only supports on iOS

Sound Effects

|    Platform     |   supported sound effects formats   |
|-----------------|:-----------------------------------:|
| Android Supports|         .ogg , .wav format.         |
| iOS             |          .mp3, .wav, .caf           |   
| Windows Desktop |         .mid and .wav only          |    

Upvotes: 1

Related Questions