我环顾四周,我看到的关于如何将 cocos2d 与 UIKit 集成的材料很少(注意:不是相反).我的意思是……例如……在 UIView 中添加 cocos sprite 动画,该动画放置在拆分视图控制器中(作为子视图).我该怎么做!?
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.
附言我做 iPhone 开发已经有一段时间了,但是对于 cocos2d 框架我是个菜鸟.
p.s. I've been doing iPhone development for a while now, but i'm a noob when it comes to cocos2d framework.
在 Cocos2d 中有一个名为 AttachDemo
的 demo,它将一个 Cocos2d 的 director 附加到一个 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");
}
}
如您所见,您需要创建一个 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 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!