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 + +