Integrating Cocos2D with UIKit

前端 未结 2 1414
悲&欢浪女
悲&欢浪女 2020-12-24 03:56

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

相关标签:
2条回答
  • 2020-12-24 04:31

    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

    0 讨论(0)
  • 2020-12-24 04:49

    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.

    0 讨论(0)
提交回复
热议问题