博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AppDelegate.h
阅读量:6720 次
发布时间:2019-06-25

本文共 5219 字,大约阅读时间需要 17 分钟。

hot3.png

#ifndef __APP_DELEGATE_H__#define __APP_DELEGATE_H__#include "CCApplication.h"//CCApplication.h能根据平台打开对应的平台头文件/**@brief    The cocos2d Application.The reason for implement as private inheritance is to hide some interface call by CCDirector.*/class  AppDelegate : private cocos2d::CCApplication{public:    AppDelegate();    virtual ~AppDelegate();    /**    @brief    Implement for initialize OpenGL instance, set source path, etc...    */    virtual bool initInstance();    /**    @brief    Implement CCDirector and CCScene init code here.    @return true    Initialize success, app continue.    @return false   Initialize failed, app terminate.    */    virtual bool applicationDidFinishLaunching();    /**    @brief  The function be called when the application enter background    @param  the pointer of the application    */    virtual void applicationDidEnterBackground();    /**    @brief  The function be called when the application enter foreground    @param  the pointer of the application    */    virtual void applicationWillEnterForeground();};#endif  // __APP_DELEGATE_H__

#include "AppDelegate.h"#include "cocos2d.h"#include "HelloWorldScene.h"#include "CCEGLView.h"USING_NS_CC;AppDelegate::AppDelegate(){}AppDelegate::~AppDelegate(){}bool AppDelegate::initInstance(){    bool bRet = false;    do    {#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)        // Initialize OpenGLView instance, that release by CCDirector when application terminate.        // The HelloWorld is designed as HVGA.        CCEGLView * pMainWnd = new CCEGLView();        CC_BREAK_IF(! pMainWnd                || ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));#endif  // CC_PLATFORM_WIN32#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)        // OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.#endif  // CC_PLATFORM_IOS#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)        // OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp        // the default setting is to create a fullscreen view        // if you want to use auto-scale, please enable view->create(320,480) in main.cpp        // if the resources under '/sdcard" or other writeable path, set it.        // warning: the audio source should in assets/        // cocos2d::CCFileUtils::setResourcePath("/sdcard");#endif  // CC_PLATFORM_ANDROID#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)        // Initialize OpenGLView instance, that release by CCDirector when application terminate.        // The HelloWorld is designed as HVGA.        CCEGLView* pMainWnd = new CCEGLView(this);        CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));#ifndef _TRANZDA_VM_        // on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file        cocos2d::CCFileUtils::setResource("HelloWorld.zip");#endif#endif  // CC_PLATFORM_WOPHONE#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)        // MaxAksenov said it's NOT a very elegant solution. I agree, haha        CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);#endif#if (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)        // Initialize OpenGLView instance, that release by CCDirector when application terminate.        // The HelloWorld is designed as HVGA.        CCEGLView * pMainWnd = new CCEGLView();        CC_BREAK_IF(! pMainWnd                || ! pMainWnd->Create("cocos2d: Hello World", 800, 480,480, 320));        CCFileUtils::setResourcePath("../Resource/");#endif  // CC_PLATFORM_LINUX#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)        CCEGLView * pMainWnd = new CCEGLView();        CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));        pMainWnd->setDeviceOrientation(Osp::Ui::ORIENTATION_LANDSCAPE);        CCFileUtils::setResourcePath("/Res/");#endif  // CC_PLATFORM_BADA#if (CC_TARGET_PLATFORM == CC_PLATFORM_QNX)        CCEGLView * pMainWnd = new CCEGLView();        CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(480, 320));        CCFileUtils::setResourcePath("./app/native/Resource");#endif // CC_PLATFORM_QNX        bRet = true;    } while (0);    return bRet;}bool AppDelegate::applicationDidFinishLaunching(){    // initialize director    CCDirector *pDirector = CCDirector::sharedDirector();    pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());    // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.//     pDirector->enableRetinaDisplay(true);    // turn on display FPS    pDirector->setDisplayFPS(true);    // set FPS. the default value is 1.0/60 if you don't call this    pDirector->setAnimationInterval(1.0 / 60);    // create a scene. it's an autorelease object    CCScene *pScene = HelloWorld::scene();    // run    pDirector->runWithScene(pScene);    return true;}// This function will be called when the app is inactive. When comes a phone call,it's be invoked toovoid AppDelegate::applicationDidEnterBackground(){    CCDirector::sharedDirector()->pause();}// this function will be called when the app is active againvoid AppDelegate::applicationWillEnterForeground(){    CCDirector::sharedDirector()->resume();}

1

转载于:https://my.oschina.net/ajian2014/blog/282621

你可能感兴趣的文章
python 回溯法 子集树模板 系列 —— 5、取物搭配问题
查看>>
1 张图秒懂 Nova 16 种操作 - 每天5分钟玩转 OpenStack(44)
查看>>
多表外连接的使用
查看>>
ORACLE rman备份之ORA-19809 ORA-19804
查看>>
《夜班医生》观后感
查看>>
SqlBulkCopy批量插入数据时,不执行触发器和约束的解决方法
查看>>
[20170315]简单探究dg的mrp进程.txt
查看>>
JQuery+CSS3实现封装弹出登录框效果
查看>>
在Visual Studio 2017中找不到.NET Framework 4.6.2
查看>>
谈长耗时任务的优化
查看>>
rpc框架之 avro 学习 2 - 高效的序列化
查看>>
回归基础性安全防护:Equifax(艾可飞)事件前车之鉴
查看>>
【妄言之言】我的2016--困境与选择
查看>>
数据库设计---关于建表的时候选择横表和竖表(纵表)的一点思考
查看>>
微信小程序开发(3) 热门电影
查看>>
二极管与、或门,三极管非门电路原理
查看>>
美图T8s真机来了!电影人像和云端AI处理是亮点
查看>>
卑不谋尊,疏不谋戚
查看>>
Docker上的MySQL:MySQL容器的单主机网络
查看>>
阿里巴巴股价大涨市值超腾讯居亚洲第一
查看>>