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 的集成
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01