2.4 AppDelegate 的 3 个生命周期
2013-11-11 23:24
465 查看
Classed/AppDelegate.cpp 文件内容如下:
#include "cocos2d.h" #include "CCEGLView.h" #include "AppDelegate.h" #include "HelloWorldScene.h" #include "SimpleAudioEngine.h" using namespace CocosDenshion; USING_NS_CC; AppDelegate::AppDelegate() { } AppDelegate::~AppDelegate() { SimpleAudioEngine::end(); } bool AppDelegate::applicationDidFinishLaunching() { // initialize director(导演初始化) CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->setOpenGLView(CCEGLView::sharedOpenGLView()); // turn on display FPS(设置显示状态信息:当前对象个数 每一帧使用时间 当前游戏整体运行帧数) pDirector->setDisplayStats(true); // set FPS. the default value is 1.0/60 if you don't call this(设置游戏帧率为每秒60帧) pDirector->setAnimationInterval(1.0 / 60); // create a scene. it's an autorelease object CCScene *pScene = HelloWorld::scene(); // run (运行 HelloWorld 场景) pDirector->runWithScene(pScene); 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() { //对整个游戏设置暂停 CCDirector::sharedDirector()->stopAnimation(); //设置暂停音乐 SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } // this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { //设置游戏继续 CCDirector::sharedDirector()->startAnimation(); //设置音乐继续播放 SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); } /* 此类含义是当整个项目启动后,Cocos2d-x引擎会从各个平台的入口函数中接管,然后调用 AppDelegate类中的 applicationDidFinishLaunching 函数。 当程序用户切入运行后台的时候,会响应 AppDelegate 类中的 applicationDidEnterBackground 函数。 当程序用户从设备运行后台切回到当前运行程序时,会响应 AppDelegate 类中的 applicationWillEnterForeground函数。 */
相关文章推荐
- app的生命周期 和UIApplicationDelegate的代理方法的调用顺序
- AppDelegate中各个方法的生命周期
- Hello Swift!<Appdelegate的生命周期以及变量定义>
- iOS学习笔记(2)AppDelegate的生命周期.
- Info.plist和pch文件的作用,UIApplication,iOS程序的启动过程,AppDelegate 方法解释,UIWindow,生命周期方法
- AppDelegate生命周期
- AppDelegate中的生命周期事件的调用条件
- AppDelegate生命周期详解
- iOS appDelegate 生命周期
- AppDelegate 内的方法在APP生命周期触发的时机和顺序
- AppDelegate生命周期详解
- Info.plist和pch文件的作用,UIApplication,iOS程序的启动过程,AppDelegate 方法解释,UIWindow,生命周期方法
- iOS程序生命周期 AppDelegate
- AppDelegate 处理iOS应用的生命周期事件
- IOS应用程序生命周期的AppDelegate详解
- Cocos2dx中AppDelegate生命周期
- AppDelegate生命周期详解
- AIR Native Extension for iOS 接入第三方sdk 如何实现 AppDelegate 生命周期
- AppDelegate生命周期详解
- iOS中Appdelegate的生命周期