标签:style blog http color io os 使用 ar for
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_
#include "cocos2d.h"
#include "SimpleAudioEngine.h" ①
using namespace CocosDenshion; ②
class AppDelegate : private cocos2d::Application
{
public:
AppDelegate();
virtual ~AppDelegate();
virtual bool applicationDidFinishLaunching();
virtual void applicationDidEnterBackground();
virtual void applicationWillEnterForeground();
};
#endif // _APP_DELEGATE_H_#include "AppDelegate.h"
#include "HelloWorldScene.h"
USING_NS_CC;
AppDelegate::AppDelegate() {
}
AppDelegate::~AppDelegate()
{
}
bool AppDelegate::applicationDidFinishLaunching() { ①
… …
// run
director->runWithScene(scene);
//初始化 背景音乐
SimpleAudioEngine::getInstance()->preloadBackgroundMusic("sound/Jazz.mp3"); ②
SimpleAudioEngine::getInstance()->preloadBackgroundMusic("sound/Synth.mp3"); ③
//初始化 音效
SimpleAudioEngine::getInstance()->preloadEffect("sound/Blip.wav"); ④
return true;
}
void AppDelegate::applicationDidEnterBackground() { ⑤
Director::getInstance()->stopAnimation();
SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); ⑥
}
void AppDelegate::applicationWillEnterForeground() { ⑦
Director::getInstance()->startAnimation();
SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); ⑧
}第⑤行代码是声明applicationDidEnterBackground()是游戏进入到后天时候调用函数,在这个函数中须要停止动画和暂停背景音乐播放。第⑦行代码是声明applicationWillEnterForeground()是游戏从后天回到前台时候调用,在这个函数中须要继续动画和背景音乐播放。
Cocos2d-x实例:设置背景音乐与音效- AppDelegate实现
标签:style blog http color io os 使用 ar for
原文地址:http://www.cnblogs.com/mengfanrong/p/3982550.html