废话不说:直接看代码注释
#include "AppDelegate.h"
#include "HelloWorldScene.h"
//USING_NS_CC == using namespace cocos2d
USING_NS_CC;//using namespace cocos2d
//构造函数
AppDelegate::AppDelegate() {
}
//析构函数
AppDelegate::~AppDelegate()
{
}
//程序初始化函数
bool AppDelegate::applicationDidFinishLaunching() {
// initialize director
//获取设备
auto director = Director::getInstance();
//取得OpenGL窗口
auto glview = director->getOpenGLView();
if(!glview) {
//如果为空,则创建以" www.sundaboke.com"为窗口标题的窗口。
glview = GLView::create("www.sundaboke.com");//这里我修改过 //刚刚开始是My Game 我修改成www.sundaboke.com cocos2dx 默认的设置的窗口大小是960,640
//设置设备使用的窗口,此句可以去掉。
//director->setOpenGLView(glview);这一句我个人医保写在下面
}
//设置设备使用的窗口,
director->setOpenGLView(glview);
// turn on display FPS
//打开FPS显示
director->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this
//设置每秒60帧
director->setAnimationInterval(1.0 / 60);
// create a scene. it's an autorelease object
//创建HelloWorld场景
auto scene = HelloWorld::createScene();
// run
//运行场景
director->runWithScene(scene);
return true;
}
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
//当收到电话时,游戏转入后台服务,响应这句话
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();
//如果使用使用,下面可以用这句代码暂停
// if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
//当电话完成,选择恢复游戏是,响应这一句
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();
// if you use SimpleAudioEngine, it must resume here
//如果使用声音,下面可以用这句代码恢复
// SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}