zoukankan      html  css  js  c++  java
  • 2.4 AppDelegate 的 3 个生命周期


    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函数。
    */
  • 相关阅读:
    分布式系统实践解读丨详解高内聚低耦合
    Git:改变世界的一次代码提交
    一分钟带你认识深度学习中的知识蒸馏
    99%的人都能看懂的分布式系统「补偿」机制
    一大波人气博主袭来,现场直播华为全联接2020!
    快速了解前端开发HTML的正确姿势
    华为云IoT智简联接,开启物联世界新纪元
    从一个小程序说起2 C++快速入门03
    从一个小程序说起 C++快速入门02
    PE格式详细讲解6(上) 系统篇06|解密系列
  • 原文地址:https://www.cnblogs.com/MrGreen/p/3418693.html
Copyright © 2011-2022 走看看