Cocos2d-x 音效

本文介绍Cocos2d-x中SimpleAudioEngine类的方法,包括背景音乐与音效的加载、播放、暂停、恢复及音量调节等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



  1. //获得SimpleAudioEngine的实例  
  2. static SimpleAudioEngine* sharedEngine();  
  3. //提前载入音频  
  4. void preloadBackgroundMusic(const charpszFilePath);  
  5. //播放背景音乐,是否循环播放  
  6. void playBackgroundMusic(const charpszFilePath, bool bLoop false);  
  7. //停止背景音乐  
  8. void stopBackgroundMusic(bool bReleaseData false);  
  9. //暂停背景音乐  
  10. void pauseBackgroundMusic();  
  11. //恢复背景音乐  
  12. void resumeBackgroundMusic();  
  13. //重新播放背景音乐  
  14. void rewindBackgroundMusic();  
  15. //是否正在播放背景音乐  
  16. bool isBackgroundMusicPlaying();  
  17. //获得背景音乐音量  
  18. float getBackgroundMusicVolume();  
  19. //设置背景音乐音量  
  20. void setBackgroundMusicVolume(float volume);  
  21. //获得音效音量  
  22. float getEffectsVolume();  
  23. //设置音效音量  
  24. void setEffectsVolume(float volume);  
  25. //播放音效,是否循环播放,返回一个内部维护的ID号  
  26. unsigned int playEffect(const charpszFilePath, bool bLoop false);  
  27. //暂停ID音效  
  28. void pauseEffect(unsigned int nSoundId);  
  29. //暂停所有音效  
  30. void pauseAllEffects();  
  31. //恢复ID音效  
  32. void resumeEffect(unsigned int nSoundId);  
  33. //恢复所有音效  
  34. void resumeAllEffects();  
  35. //停止ID音效  
  36. void stopEffect(unsigned int nSoundId);  
  37. //停止所有音效  
  38. void stopAllEffects();  
  39. //提前载入音效  
  40. void preloadEffect(const charpszFilePath);  
  41. //释放音效  
  42. void unloadEffect(const charpszFilePath);  
  43. 增大音量SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() 0.1f);  
  1. http://blog.youkuaiyun.com/a351945755/article/details/7947593

  1. //获得SimpleAudioEngine的实例  
  2. static SimpleAudioEngine* sharedEngine();  
  3. //提前载入音频  
  4. void preloadBackgroundMusic(const charpszFilePath);  
  5. //播放背景音乐,是否循环播放  
  6. void playBackgroundMusic(const charpszFilePath, bool bLoop false);  
  7. //停止背景音乐  
  8. void stopBackgroundMusic(bool bReleaseData false);  
  9. //暂停背景音乐  
  10. void pauseBackgroundMusic();  
  11. //恢复背景音乐  
  12. void resumeBackgroundMusic();  
  13. //重新播放背景音乐  
  14. void rewindBackgroundMusic();  
  15. //是否正在播放背景音乐  
  16. bool isBackgroundMusicPlaying();  
  17. //获得背景音乐音量  
  18. float getBackgroundMusicVolume();  
  19. //设置背景音乐音量  
  20. void setBackgroundMusicVolume(float volume);  
  21. //获得音效音量  
  22. float getEffectsVolume();  
  23. //设置音效音量  
  24. void setEffectsVolume(float volume);  
  25. //播放音效,是否循环播放,返回一个内部维护的ID号  
  26. unsigned int playEffect(const charpszFilePath, bool bLoop false);  
  27. //暂停ID音效  
  28. void pauseEffect(unsigned int nSoundId);  
  29. //暂停所有音效  
  30. void pauseAllEffects();  
  31. //恢复ID音效  
  32. void resumeEffect(unsigned int nSoundId);  
  33. //恢复所有音效  
  34. void resumeAllEffects();  
  35. //停止ID音效  
  36. void stopEffect(unsigned int nSoundId);  
  37. //停止所有音效  
  38. void stopAllEffects();  
  39. //提前载入音效  
  40. void preloadEffect(const charpszFilePath);  
  41. //释放音效  
  42. void unloadEffect(const charpszFilePath);  
  43. 增大音量SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() 0.1f);  
  1. http://blog.youkuaiyun.com/a351945755/article/details/7947593
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值