Skip to content

Instantly share code, notes, and snippets.

@sdkfz181tiger
Last active December 26, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdkfz181tiger/7163672 to your computer and use it in GitHub Desktop.
Save sdkfz181tiger/7163672 to your computer and use it in GitHub Desktop.
サウンド制御
//
// UtilSound.cpp
// HelloCpp
//
// Created by Shimeji Ozaki on 2013-10-16.
//
//
#include "UtilSound.h"
void UtilSound::makeSounds(){
// SimpleAudioEngine
CocosDenshion::SimpleAudioEngine* sae = CocosDenshion::SimpleAudioEngine::getInstance();
// Volume
sae->setBackgroundMusicVolume(0.5f);
sae->setEffectsVolume(0.5f);
{
// BGM
const char* fileNames[] = {
"bgm_title.mp3",
"bgm_op.mp3",
"bgm_title.mp3"
"bgm_oyaji.mp3"
};
// sizeof(array) ←全体のサイズ
// sizeof(*array) ←ポインタ位置にある要素のサイズ
int count = sizeof(fileNames) / sizeof(*fileNames);
for(int i=0; i<count; i++){
sae->preloadBackgroundMusic(fileNames[i]);
}
}
{
// SE
const char* fileNames[] = {
"se_talk.mp3"
};
int count = sizeof(fileNames) / sizeof(*fileNames);
for(int i=0; i<count; i++){
sae->preloadEffect(fileNames[i]);
}
}
}
void UtilSound::playBGM(const char* fileName){
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(fileName);
}
void UtilSound::playBGM(const char* fileName, bool loop){
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(fileName, loop);
}
void UtilSound::stopBGM(){
CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic();
}
int UtilSound::playSE(const char* fileName){
int id = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(fileName);
return id;
}
int UtilSound::playSE(const char* fileName, int loop){
int id = CocosDenshion::SimpleAudioEngine::getInstance()->playEffect(fileName, loop);
return id;
}
void UtilSound::stopSE(int id){
CocosDenshion::SimpleAudioEngine::getInstance()->stopEffect(id);
}
void UtilSound::stopAllSE(){
CocosDenshion::SimpleAudioEngine::getInstance()->stopAllEffects();
}
//
// UtilSound.h
// HelloCpp
//
// Created by Shimeji Ozaki on 2013-10-16.
//
//
#ifndef __HelloCpp__UtilSound__
#define __HelloCpp__UtilSound__
#include "cocos2d.h"
#include "SimpleAudioEngine.h"
USING_NS_CC;
class UtilSound{
public:
static void makeSounds();
static void playBGM(const char* fileName);
static void playBGM(const char* fileName, bool loop);
static void stopBGM();
static int playSE(const char* fileName);
static int playSE(const char* fileName, int loop);
static void stopSE(int id);
static void stopAllSE();
};
#endif /* defined(__HelloCpp__UtilSound__) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment