Cocos2D 与 UIKit 的集成

2024-04-14移动开发问题
3

本文介绍了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 的集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21