Integrating Cocos2D with UIKit(Cocos2D 与 UIKit 的集成)
问题描述
我环顾四周,我看到的关于如何将 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 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Cocos2D 与 UIKit 的集成
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01