cocos2dx之AppDelegate

本文解析了AppDelegate在Cocos2d-x项目中的作用及初始化流程,并详细介绍了AppDelegate的几个关键方法,包括程序入口、应用启动完成、应用进入后台及应用再次激活。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在创建完了工程之后,我们可以看到AppDelegate这个文件,我们打开看下这里面有什么:

AppDelegate::AppDelegate() { //1,构造AppDelegate

}

AppDelegate::~AppDelegate() 
{
}

bool AppDelegate::applicationDidFinishLaunching() {//3,在2初始化完之后进入,结束初始化appDelegate
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	
    // turn on display FPS
    pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

	CCScene * pScene = CCScene::create();
    GameDemoManager * pLayer = new GameDemoManager();
	pLayer->initGame();
    pLayer->autorelease();

    pScene->addChild(pLayer);
    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() {//4,当手机处于后台运行的时候,进入该处
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() { /,2,构造完了AppDelegate之后进入初始化application
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}

从上面分析:

AppDelegate其实就是整个程序的入口,它的初始化步骤就是上面的1-3,4则是在手机后台运行该程序时所调用的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值