cocos2dx 编写消灭星星音效加载

前端之家收集整理的这篇文章主要介绍了cocos2dx 编写消灭星星音效加载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一个游戏,声音也是非常的重要,其实cocos2dx里面的简单音效引擎的使用是非常简单的。我这里只不过是用一个类对所有的音效进行管理罢了。
Audio.h
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef _AUdio_H_
#define _AUdio_H_
class Audio{
public :
static Audio* getInstance();
void playBGM();
playReadyGo();
playPop();
prepare();
playCombo( int size);
private :
Audio* m_instance;
};
#endif

Audio.cpp
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "Audio.h"
#include "SimpleAudioEngine.h"
Audio* Audio::m_instance = nullptr ;
Audio* Audio::getInstance(){
if (m_instance == ){
m_instance = new Audio();
}
return m_instance;
}
Audio::playBGM(){
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic( "Music/music.ogg" , true );
}
Audio::playReadyGo(){
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect( "Music/readygo.ogg" false );
}
Audio::playPop(){
"Music/pop.ogg" );
}
Audio::playCombo( @H_474_301@size){
(size < 5)
;
(size >= 10){
"Music/combo_3.ogg" );
} else (size >= 7){
"Music/combo_2.ogg" );
else {
"Music/combo_1.ogg" );
}
}
Audio::prepare(){
CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic( );
CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect( );
);
);
);
);
}

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