since I did games with the entire cocos2d till now and I'm working for the first time on a project with a UIViewController which is responsible to start the game scenes, I'm wondering how should I do, since the appDelegate is starting with a normal UIViewController, how could I set a method on a button to start the game (e.g the fist scene of the game) ? I've been searching for example or discussion about this but I didn't found anything, every example I saw was starting the game scene from the appDelegate at the first call.
2
votes
did you try to set the controller's view with the openglview created at startup ?
– giorashc
you mean instead of setting the navController with the root director, and call the director with setview:glview I could do the same with my custom view controller?
– Adarkuccio
Never tried it but you could give it a shot.
– giorashc
You can start project by installing cocos2d framework into Xcode and choose project with cocos2d. No need to add extra code. Cocos2d framework will add all code.
– Rajesh Maurya
1 Answers
0
votes
Just import your cocos2d layer.h and layer.m files and to call from view controller use the following code:-
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [EAGLView viewWithFrame:[self.view bounds]
pixelFormat:kEAGLColorFormatRGB565 depthFormat:0];
[director setOpenGLView:glView];
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
[director setAnimationInterval:1.0/60];
[director setDisplayFPS:YES];
[self setView:glView];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];