cocos2d 基于AudioEngine.h创建的封装类AudioManage

ifndef AUDIOMANAGE_H

define AUDIOMANAGE_H

include

using namespace std;
class AudioManage
{
public:static AudioManage*getInstance();
void stopMusic(int musid);
void stopMusicById(int id);
int playMusic(std::string musicname, bool isloop);
bool addMusicIntoBox(std::string musickey, std::string musicname);
std::string getMusicFromBox(std::string musickey);
private:
static map”左尖括号”std::string,std::string”右尖括号”musicBox;
};

endif

include”AudioManage.h”

include”AudioEngine.h”

include”cocos2d.h”

using namespace cocos2d::experimental;
using namespace::std
map std::string, std::string AudioManage::musicBox;
static AudioManage* _Instance=nullptr;
AudioManage* AudioManage::getInstance() {
if (_Instance==nullptr) {

    return new AudioManage();
}

return _Instance;

}

void AudioManage::stopMusic(int musid) {
AudioEngine::stop(musid);
}

void AudioManage::stopMusicById(int id) {
AudioEngine::stop(id);
}

int AudioManage::playMusic(std::string musicName,bool isLoop) {
int musicID=AudioEngine::play2d(musicName,isLoop);
return musicID;
};

bool AudioManage::addMusicIntoBox(std::string musickey, std::string musicname) {
int sizebef = musicBox.size();
musicBox.insert(map “左尖括号”std::string, std::string”右尖括号”::value_type(musickey,musicname));
int sizeaft = musicBox.size();
if (sizeaft-sizebef!=1) {
return false;
}
else
{
return true;
}

};

std::string AudioManage::getMusicFromBox(std::string musickey) {
string musicname = musicBox[musickey];

return musicname;

};

你可能感兴趣的:(game)