SimpleAudioEngine

前端之家收集整理的这篇文章主要介绍了SimpleAudioEngine前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

说明

引擎版本:cocos2d-x 3.4 编译器:visual studio 2013 UI编辑器:Cocos Studio v1.6.0.0

SimpleAudioEngine(/cocosdension模块下)

文件、命名空间
    
    
#include "audio/include/SimpleAudioEngine.h"using namespace CocosDenshion;

主要播放两类声音:背景音乐、音效
不同平台,声音的格式不一定相同,下面是推荐的在各平台播放的声音格式:

背景音乐 音效
Win32 MP3、MID、WAV MID、WAV
Android OGG
IOS MP3、CAF CAF
这个类内容不多,用法也很简单:
  • class EXPORT_DLL SimpleAudioEngine{public:static SimpleAudioEngine* getInstance(); /** @brief Release the shared Engine object @warning It must be called before the application exit,or a memory leak will be casued.(程序关闭前,记得释放,以防内存泄漏) */void end();protectedvirtual ~SimpleAudioEngine @brief Preload background music @param pszFilePath The path of the background music file. * @js preloadMusic * @lua preloadMusic preloadBackgroundMusic(constchar pszFilePath); @brief Play background music @param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo @param bLoop Whether the background music loop or not * @js playMusic * @lua playMusic playBackgroundMusic,bool bLoop =false @brief Stop playing background music @param bReleaseData If release the background music data or not.As default value is false * @js stopMusic * @lua stopMusic stopBackgroundMusic bReleaseData @brief Pause playing background music * @js pauseMusic * @lua pauseMusic pauseBackgroundMusic @brief Resume playing background music * @js resumeMusic * @lua resumeMusic resumeBackgroundMusic @brief Rewind playing background music * @js rewindMusic * @lua rewindMusic rewindBackgroundMusic @brief Indicates whether any background music can be played or not. @return <i>true</i> if background music can be played,otherwise <i>false</i>. * @js willPlayMusic * @lua willPlayMusic willPlayBackgroundMusic @brief Indicates whether the background music is playing @return <i>true</i> if the background music is playing,otherwise <i>false</i> * @js isMusicPlaying * @lua isMusicPlaying isBackgroundMusicPlaying @brief The volume of the background music within the range of 0.0 as the minimum and 1.0 as the maximum. * @js getMusicVolume * @lua getMusicVolume float getBackgroundMusicVolume @brief Set the volume of background music @param volume must be within the range of 0.0 as the minimum and 1.0 as the maximum. * @js setMusicVolume * @lua setMusicVolume setBackgroundMusicVolume(float volume// // 音效模块 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @brief The volume of the effects within the range of 0.0 as the minimum and 1.0 as the maximum. getEffectsVolume @brief Set the volume of sound effects setEffectsVolume @brief Play sound effect with a file path,pitch,pan and gain @param pszFilePath The path of the effect file. @param bLoop 是否循环播放,默认为false @param pitch 频率,normal value is 1.0. Will also change effect play time. @param pan 声道,in the range of [-1..1] where -1 enables only left channel. @param gain 音量,in the range of [0..1]. The normal value is 1. @return the OpenAL source id @note Full support is under development,now there are limitations: - no pitch effect on Samsung Galaxy S2 with OpenSL backend enabled; - no pitch/pan/gain on emscrippten,win32,marmalade.unsigned int playEffect pitch 1.0f pan 0.0f gain @brief Pause playing sound effect @param nSoundId The return value of function playEffect pauseEffect nSoundId @brief Pause all playing sound effect pauseAllEffects @brief Resume playing sound effect resumeEffect @brief Resume all playing sound effect resumeAllEffects @brief Stop playing sound effect stopEffect @brief Stop all playing sound effects stopAllEffects @brief preload a compressed audio file @details the compressed audio will be decoded to wave,then written into an internal buffer in SimpleAudioEngine @param pszFilePath The path of the effect file preloadEffect @brief unload the preloaded effect from internal buffer unloadEffect);};
    原文链接:https://www.f2er.com/cocos2dx/339073.html

    猜你在找的Cocos2d-x相关文章