zoukankan      html  css  js  c++  java
  • 3.cocos代码入口

     模拟代码进入过程:

    • main.cpp
       1 #include <iostream>
       2 #include "AppDelegate.h"
       3 #include "CCApplication.h"
       4 #include "CCApplicationProtocol.h"
       5 using namespace std;
       6 
       7 int main()
       8 {
       9     AppDelegate app;
      10 
      11     return CCApplication::sharedApplication()->run();
      12 }
    • AppDelegate.h
       1 #pragma once
       2 #include "CCApplication.h"
       3 class AppDelegate :
       4     public CCApplication
       5 {
       6 public:
       7     AppDelegate();
       8     virtual ~AppDelegate();
       9 
      10     virtual bool applicationDidFinishLaunching();//子类实现了接口
      11 };
    • AppDelegate.cpp
      #include "AppDelegate.h"
      #include <Windows.h>
      
      
      AppDelegate::AppDelegate()
      {
      }
      
      
      AppDelegate::~AppDelegate()
      {
      }
      //真正的入口
      bool AppDelegate::applicationDidFinishLaunching() { MessageBoxA(0, "游戏开始", "提示", 1); return false; }
    • CCApplication.h
       1 #pragma once
       2 #include "CCApplicationProtocol.h"
       3 
       4 class CCApplication :
       5     public CCApplicationProtocol
       6 {
       7 public:
       8     CCApplication();
       9     virtual ~CCApplication();
      10 
      11     int run();
      12 
      13     static CCApplication *sharedApplication();
      14     static CCApplication *sm_pSharedApplication;
      15 };
    • CCApplication.cpp
       1 #include "CCApplication.h"
       2 #include "stddef.h"
       3 
       4 CCApplication * CCApplication::sm_pSharedApplication = NULL;
       5 
       6 CCApplication::CCApplication()
       7 {
       8     sm_pSharedApplication = this;//注意这个this是子类AppDelegate传过来的
       9 }
      10 
      11 
      12 CCApplication::~CCApplication()
      13 {
      14 }
      15 //run调用父类的applicationDidFinishLaunching()方法,父类的方法在子类中实现
      16 int CCApplication::run()
      17 {
      18     applicationDidFinishLaunching();
      19     return 0;
      20 }
      21 
      22 CCApplication * CCApplication::sharedApplication()
      23 {
      24     if(sm_pSharedApplication != NULL)
      25         return sm_pSharedApplication;
      26 }
    • CCApplicationProtocol.h
      1 #pragma once
      2 class CCApplicationProtocol
      3 {
      4 public:
      5     CCApplicationProtocol();
      6     virtual ~CCApplicationProtocol();
      7 
      8     virtual bool applicationDidFinishLaunching() = 0;
      9 };
    • CCApplicationProtocol.cpp
      #include "CCApplicationProtocol.h"
      
      
      
      CCApplicationProtocol::CCApplicationProtocol()
      {
      }
      
      
      CCApplicationProtocol::~CCApplicationProtocol()
      {
      }

    运行截图:

  • 相关阅读:
    iOS的生命周期
    【iOS开发】在 App 中加入 AdMob 广告
    iOS性能优化:Instruments
    动态的计算行高 加载数据源 有多少显示多少 tableView 包含 colloctionView 显示复杂的界面写法
    Java String.split()注意点
    Java eclipse export jar包 包括第三方引入的jar
    微信网页授权获取用户基本信息
    android连接本地tomcat服务器,报timeout
    iOS内存管理retain,assign,copy,strong,weak
    static与全局与局部变量的区别
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8337074.html
Copyright © 2011-2022 走看看