游戏中声音主要包含2个方面,背景声音和特效。SimpleAudioEngine的API 也是这么设计的。你可以简单方便的使用它。该有的功能都已经有了。
01 |
//获得SimpleAudioEngine的实例 |
02 |
static SimpleAudioEngine*
sharedEngine(); |
03 |
//提前载入音频 |
04 |
void preloadBackgroundMusic( const char *
pszFilePath); |
05 |
//播放背景音乐,是否循环播放 |
06 |
void playBackgroundMusic( const char *
pszFilePath, bool bLoop
= false ); |
07 |
//停止背景音乐 |
08 |
void stopBackgroundMusic( bool bReleaseData
= false ); |
09 |
//暂停背景音乐 |
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 char *
pszFilePath, 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 char *
pszFilePath); |
41 |
//释放音效 |
42 |
void unloadEffect( const char *
pszFilePath); |
增大音量代码:
1 |
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume( |
2 |
SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()
+ 0.1f); |