Compare apps;
The start-up process for an app is:
int Main (intChar * argv[]) { @autoreleasepool { return@ " appdelegate");} }
Corresponding
@interface Appdelegate:uiresponder <UIApplicationDelegate>*window; @end
In the
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions { // Override point for customization after application launch. // Create window Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds]; [Self.window makekeyandvisible]; *view = [[Maintableviewcontroller alloc]init]; // Root View Self.window.rootViewController = view; return YES;}
Can see the key is
Window.rootviewcontroller
The start-up process in cocos2d-x is basically the same:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {cocos2d::application*app =cocos2d::application::getinstance (); ... Cceaglview*eaglview =[Cceaglview viewwithframe: [window bounds] ...//Eaglview Inheritance UIView[Eaglview Setmultipletouchenabled:yes]; Viewcontroller.view= Eaglview;//Place to joinCocos2d::glview*glview =Cocos2d::glviewimpl::createwitheaglview (Eaglview); //TODO: The need to encapsulate more than one layer needs to be understood in conjunction with AndroidCocos2d::D irector::getinstance ()Setopenglview (Glview); App->run ();//Go in here and enter the game loop . returnYES;}
There are 3 somewhat confusing classes:
AppController is iOS, it's better to differentiate
Application and Appdelegate:
Application: Personal understanding is equivalent to MFC in the APP class, there is a similar run interface, corresponding to the game main loop.
And then
Class Appdelegate:private Cocos2d::application
Then there is the Director is mainly the operation of the corresponding Glview.
Run and go in.
-(void) startmainloop{ // Director::setanimationinterval () is called, we should Invalidate itfirst [self stopmainloop]; = [Nsclassfromstring (@ "cadisplaylink") displaylinkwithtarget:self selector:@ Selector (docaller:)]; [DisplayLink SetFrameInterval:self.interval]; [DisplayLink Addtorunloop:[nsrunloop Currentrunloop] formode:nsdefaultrunloopmode];}
[DisplayLink Addtorunloop:[nsrunloop Currentrunloop] formode:nsdefaultrunloopmode];
Understand:
Nsrunloop is in the Foundation framework
Cocos2d-x Simple recording of the engagement on iOS