void MainScene::preloadMusic() { SimpleAudioEngine *pAudioEngine = SimpleAudioEngine::sharedEngine(); pAudioEngine->preloadBackgroundMusic(BACK_MUSIC); pAudioEngine->preloadEffect(JUMP_MUSIC); pAudioEngine->preloadEffect(CROUCH_MUSIC); }
static mrb_value SimpleAudioEngine_preloadEffect(mrb_state *mrb, mrb_value self) { mrb_value* args; int arg_count; mrb_get_args(mrb, "*", &args, &arg_count); const char* p0 = mrb_string_value_ptr(mrb, args[0]); SimpleAudioEngine* instance = static_cast<SimpleAudioEngine*>(DATA_PTR(self)); instance->preloadEffect(p0); return mrb_nil_value(); }
static mrb_value SimpleAudioEngine_stopEffect(mrb_state *mrb, mrb_value self) { mrb_value* args; int arg_count; mrb_get_args(mrb, "*", &args, &arg_count); unsigned int p0 = get_int(args[0]); SimpleAudioEngine* instance = static_cast<SimpleAudioEngine*>(DATA_PTR(self)); instance->stopEffect(p0); return mrb_nil_value(); }
KDvoid GameManager::showMenu ( KDvoid ) { m_eGameState = MainMenu; CCDirector::sharedDirector ( )->popScene ( ); SimpleAudioEngine* pSE = SimpleAudioEngine::sharedEngine ( ); if ( !pSE->isBackgroundMusicPlaying ( ) && m_bMusicOn ) { pSE->preloadBackgroundMusic ( "titletheme.mp3" ); } }
void MainScene::PlayStopBGM() { SimpleAudioEngine* audio = SimpleAudioEngine::getInstance(); if (audio->isBackgroundMusicPlaying()) { audio->stopBackgroundMusic(); } else { audio->playBackgroundMusic("musics/bgm.mp3"); } }
bool AppDelegate::applicationDidFinishLaunching() { // initialize director auto director = Director::getInstance(); auto glview = director->getOpenGLView(); if(!glview) { glview = GLView::create("My Game"); director->setOpenGLView(glview); } glview->setDesignResolutionSize(768, 1024, ResolutionPolicy::EXACT_FIT); FileUtils* futils = FileUtils::getInstance(); auto screensize = glview->getFrameSize(); if(screensize.width > 768) { vector<string> dirs(1, "hd"); futils->setSearchResolutionsOrder(dirs); director->setContentScaleFactor(2); } else { vector<string> dirs(1, "sd"); futils->setSearchResolutionsOrder(dirs); director->setContentScaleFactor(1); } SimpleAudioEngine* augine = SimpleAudioEngine::getInstance(); augine->preloadEffect(futils->fullPathForFilename("hit.wav").c_str()); augine->preloadEffect(futils->fullPathForFilename("score.wav").c_str()); // turn on display FPS director->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this director->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object auto scene = LogoLayer::createScene(); // run director->runWithScene(scene); return true; }
static mrb_value SimpleAudioEngine_playBackgroundMusic(mrb_state *mrb, mrb_value self) { mrb_value* args; int arg_count; mrb_get_args(mrb, "*", &args, &arg_count); if (arg_count == 1) { const char* p0 = mrb_string_value_ptr(mrb, args[0]); SimpleAudioEngine* instance = static_cast<SimpleAudioEngine*>(DATA_PTR(self)); instance->playBackgroundMusic(p0); return mrb_nil_value(); } else if (arg_count == 2) { const char* p0 = mrb_string_value_ptr(mrb, args[0]); bool p1 = get_bool(args[1]); SimpleAudioEngine* instance = static_cast<SimpleAudioEngine*>(DATA_PTR(self)); instance->playBackgroundMusic(p0, p1); return mrb_nil_value(); } else { mrb_raise(mrb, E_ARGUMENT_ERROR, "SimpleAudioEngine#playBackgroundMusic Wrong count of arguments."); return mrb_nil_value(); } }
void LoadingScene::preloadSounds() { SimpleAudioEngine* audioEngine = SimpleAudioEngine::getInstance(); audioEngine->stopBackgroundMusic(); audioEngine->preloadEffect(EFFECT_SPACESHIP_CREATION); audioEngine->preloadEffect(EFFECT_BOOM_2); audioEngine->preloadEffect(EFFECT_BOOM); audioEngine->playBackgroundMusic(MUSIC_GAME); }
KDbool SoundManager::init ( KDvoid ) { SimpleAudioEngine* pSE = SimpleAudioEngine::sharedEngine ( ); // sound loading pSE->preloadEffect ( "sound_fx_chip_was_unselected.wav" ); pSE->preloadEffect ( "sound_fx_regeneration.wav" ); pSE->preloadEffect ( "sound_fx_selected_chip.wav" ); pSE->preloadEffect ( "sound_fx_tap.wav" ); pSE->preloadEffect ( "sound_fx_ready.wav" ); pSE->preloadEffect ( "sound_fx_new_girl.mp3" ); pSE->preloadEffect ( "sound_fx_incorrect_matching.mp3" ); pSE->preloadEffect ( "sound_fx_game_over.mp3" ); pSE->preloadEffect ( "sound_fx_correct_matching_with_wildcard.mp3" ); pSE->preloadEffect ( "sound_fx_correct_matching.mp3" ); // music pSE->preloadBackgroundMusic ( "sound_music_game.mp3" ); pSE->preloadBackgroundMusic ( "sound_music_menu.mp3" ); return KD_TRUE; }
static void stopBackground(bool bReleaseData) { SimpleAudioEngine *engine = SimpleAudioEngine::getInstance(); engine->stopBackgroundMusic(); }
static mrb_value SimpleAudioEngine_stopAllEffects(mrb_state *mrb, mrb_value self) { SimpleAudioEngine* instance = static_cast<SimpleAudioEngine*>(DATA_PTR(self)); instance->stopAllEffects(); return mrb_nil_value(); }
APSAudioHolder::APSAudioHolder(const char *code, APSResourceManager *manager) : APSMedium(code, manager), APSAudioHolder_propertyInitialization { } APSAudioHolder::APSAudioHolder(APSDictionary *properties) : APSAudioHolder_propertyInitialization { if (properties) { this->initWithProperties(properties); } } APSAudioHolder::~APSAudioHolder() { APS_SAFE_DELETE(m_filePath) } bool APSAudioHolder::initWithProperties(APSDictionary *properties) { if(!APSMedium::initWithProperties(properties)) return false; // isBackground APSNumber *number = (APSNumber *)properties->getObjectForKey(this->getIsBackgroundKey()); if (number) { this->setIsBackground(number->getBoolean()); } return true; } void APSAudioHolder::clearCachedData() { if (!this->getRunningAction()) { if (this->getIsBackground()) { } else { SimpleAudioEngine *engine = SimpleAudioEngine::sharedEngine(); engine->unloadEffect(this->getFilePath()->c_str()); } } APSMedium::clearCachedData(); } void APSAudioHolder::preloadData() { if (this->getIsBackground()) { SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(this->getFilePath()->c_str()); } else { SimpleAudioEngine::sharedEngine()->preloadEffect(this->getFilePath()->c_str()); } } void APSAudioHolder::playForAction(APSAction *action) { if (this->getRunningAction()) { this->stopForAction(this->getRunningAction()); } if (this->getIsBackground()) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic(this->getFilePath()->c_str()); } else { this->setEffectId(SimpleAudioEngine::sharedEngine()->playEffect(this->getFilePath()->c_str())); } this->setRunningAction(action); } void APSAudioHolder::stopForAction(APSAction *action) { // Only the action that ran currently playing sound can stop it. if (this->getRunningAction()==action) { if (this->getIsBackground()) { SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); } else { SimpleAudioEngine::sharedEngine()->stopEffect(this->getEffectId()); } this->setRunningAction(NULL); } } const string *APSAudioHolder::getFilePath() { if (!m_filePath) { m_filePath = new string(this->getResourceManager()->getPathForFilename(this->getFilename())); } return m_filePath; } APS_END_NAMESPACE