【问题标题】:Unable to hear the sound effect in cocos2dxcocos2dx听不到音效
【发布时间】:2017-05-18 11:08:44
【问题描述】:

我有以下代码,问题是battle.mp3音乐播放正常,但是bang.mp3音效不播放。有任何想法吗?

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");

我尝试在敌方角色受到伤害时播放以下音效,但听不到任何声音。

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

【问题讨论】:

  • 您尝试在哪个平台上运行?

标签: c++ audio cocos2d-x


【解决方案1】:

使用SimpleAudioEngine::getInstance() 而不是SimpleAudioEngine::sharedEngine(),因为sharedEngine() 现在已被弃用。

音效方面,.mp3 仅支持 iOS

音效

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

【讨论】:

  • mp3 适用于 android,aac 适用于 ios 和大多数 android 设备。
  • 它是否适用于 cocos2d-x 中的SoundEffects。我还没有在 cocos2d-x 中测试过.mp3,但我已经在 cocos2d-x wiki 中测试过 link
  • 此 wiki 已过时 AF。
  • 谢谢 Abhishek Aryan,问题是我一直使用 mp3 作为音效。使用 Wav 解决。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多