The real entrance to the Cocos Game, demo version implemented in C + +

Source: Internet
Author: User

Starting point for 1.cocos games

In the main function there is a sentence: return ccapplication::sharedapplication ()->run ();

2. After layers of deep discovery, the real entrance: bool Appdelegate::applicationdidfinishlaunching ()

3. Class inheritance diagram:

4. Code implementation:

The Ccapplicationprotocol header file is as follows and the. cpp file is empty

#pragma onceclass  ccapplicationprotocol{public:    /*  Defines a virtual interface for the real entrance to the game */    virtualbool0;};

CCApplication.h

#pragmaOnce#include"CCApplicationProtocol.h"#include<iostream>using namespacestd;classCcapplication: Publicccapplicationprotocol{ Public: Ccapplication (); /*Run Method*/    Virtual intrun (); /*returns a static pointer*/    Staticccapplication*sharedapplication ();protected:    /*static pointers for implementing a singleton*/    StaticCcapplication *sm_psharedapplication;};

CCApplication.cpp

#include"CCApplication.h"/*CPP file, initialize static members*/ccapplication* Ccapplication::sm_psharedapplication =NULL; Ccapplication::ccapplication () {/*assign a child class object to a static pointer to the parent class*/sm_psharedapplication= This;} Ccapplication*ccapplication::sharedapplication () {/*implementing a single case*/    if(Sm_psharedapplication! =NULL)returnsm_psharedapplication;}intCcapplication::run () {/*Call the parent class method to implement the game startup*/applicationdidfinishlaunching (); return 0;}

AppDelegate.h

#pragma once"CCApplication.h"class appdelegate:Private  ccapplication{public:    /* implements the inherited Grandfather class method * /    virtualbool  applicationdidfinishlaunching ();};

AppDelegate.cpp

" AppDelegate.h " /* implemented the inherited Grandfather class method */ BOOL appdelegate::applicationdidfinishlaunching () {    /*Somethint to iniialize the game */       "game start" << Endl;      return true ;}

Test code:

" AppDelegate.h " int Main () {    appdelegate app;    Ccapplication::sharedapplication (),Run ();    System ("pause");     return 0 ;}

The real entrance to the Cocos Game, demo version implemented in C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.