将Cocos2D与UIKit集成 [英] Integrating Cocos2D with UIKit
问题描述
我已经看过,我已经看到很少的材料,如何集成cocos2d与UIKit(注意:不是相反)。我的意思是...例如...在UIView中添加一个cocos精灵动画,它放在一个分割视图控制器(作为子视图)。
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 cocos sprite animation inside a UIView, which is placed inside a split-view controller (as a subview). How can i do that!?
我想从UISplitView项目模板或UITabBar项目模板开始。
I want to start with a UISplitView project template or the UITabBar project template.
ps
推荐答案
现在我已经做了iPhone开发了一段时间,但是对于cocos2d框架我是一个noob。有一个演示在Cocos2d调用 AttachDemo
,其中它附加一个Cocos2d导演到 UIView
。如果你检查 - (void)runCocos2d
的方法。
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");
}
}
如您所见, code> EAGLView ,将一个导演附加到它,然后简单地将该视图添加到视图层次结构。
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.
这篇关于将Cocos2D与UIKit集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!