I\'ve looked around, and i\'ve seen very little material on how to integrate cocos2d with UIKit (note: not the other way around). What i mean is... for example... adding a c
Here is the link of the demo @pgb is referring to, http://code.google.com/p/cocos2d-iphone/source/browse/trunk/tests/attachDemo/attachDemo.m?r=1682
There's a demo in Cocos2d called AttachDemo
, where it attaches a Cocos2d director to a UIView
. If you check the method called -(void)runCocos2d
.
If you look at its code, it does the following:
-(void) runCocos2d
{
if( state == kStateEnd ) {
EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, 250,350)];
[mainView addSubview:glview];
CCDirector *director = [CCDirector sharedDirector];
[director setOpenGLView:glview];
CCScene *scene = [CCScene node];
id node = [LayerExample node];
[scene addChild: node];
[director runWithScene:scene];
state = kStateRun;
}
else {
NSLog(@"End the view before running it");
}
}
As you can see, you need to create a EAGLView
, attach a director to it, and then simply add that view to the view hierarchy.