Main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
[pool release];
return retVal;
}
AppController.mm
// cocos2d application instance
static AppDelegate* s_sharedApplication = nullptr;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//run the cocos2d-x game scene
app->run();
libcocos2d iOS/platform/ios/CCApplication-ios
int CCApplication::run()
{
if (applicationDidFinishLaunching())
{
[[CCDirectorCaller sharedDirectorCaller] startMainLoop];
}
return 0;
run方法里面首先调用了applicationDidFinishLaunching,这个函数其实才是逻辑上的app入口,我们一般在这里面写应用的初始化设置,设置分辨率设计模式,设置帧数什么的。 [[ CCDirectorCaller sharedDirectorCaller ] startMainLoop ]这句代码调用了CCDirectorCaller的startMainLoop方法,它的代码如下
-(void) startMainLoop
{
// Director::setAnimationInterval() is called, we should invalidate it first
[self stopMainLoop];
displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(doCaller:)];
[displayLink setFrameInterval: self.interval];
[displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
-(void) stopMainLoop
{
[displayLink invalidate];
displayLink = nil;
}
未完待续。。。