CCDirecter用UIView / nib替换场景 [英] CCDirecter replace scene with UIView / nib

查看:155
本文介绍了CCDirecter用UIView / nib替换场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是让Cocos2d共享导演用UIKit中的UIView替换当前场景(可能从nib加载)。这个想法是在Cocos2d和UIKit之间干净地过渡。

What I would like to do is have the Cocos2d shared director to replace the current scene with a UIView from UIKit (possibly loaded from a nib). The idea being to cleanly transition between Cocos2d and UIKit.

我已经看到了这个问题的几种方法。他们大多是关于在同一个场景中混合UIKit和Cocos2d,我想保持它们分开。一种方法是添加一个UIView的实例作为GLView导演的子视图。像这样:

I've seen a few approaches to this problem. Most of them are about mixing UIKit with Cocos2d in the same scene, I'd like to keep them separate. One approach is to add an instance of UIView as a subview of the directors GLView. Like so:

UIView* cocosView = [[CCDirector sharedDirector] openGLView];
[cocosView addSubview:t];

将一个UIView覆盖到Cocos层上?

这样可以工作,但是我必须创建一个空白场景转换到那第一,然后添加UIView,然后删除它,并转换到任何其他场景。这是模块化的,但有点凌乱。

This works but I would have to create a blank scene and transition to that first, then add the UIView, then later remove it and transition to whatever other scene. That's modular but a little messy.

一个更好的方法是将UIView包装到节点。类似:
http://www.cocos2d-iphone.org/forum/ topic / 6889

A better approach is to wrap a UIView into a node. Something like: http://www.cocos2d-iphone.org/forum/topic/6889

有没有官方cocos2d扩展名?我也想从storyboard / nib加载UIView,如果可能的话。很有必要。

Is there an official cocos2d extension for this? I'd also like to load the UIView from storyboard/nib if possible. Much obliged.

推荐答案


使用UIKit中的UIView替换当前场景

replace the current scene with a UIView from UIKit

如果您使用cocos2d 1.x: http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit

if you are using cocos2d 1.x: http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit

如果您使用cocos2d 2.x:CCDirector是UIViewController的子类,因此您可以使用常用方法。有一个错误,在停止/开始动画,但很容易解决。

if you are using cocos2d 2.x: CCDirector is a subclass of UIViewController, so you can use usual methods. There's a little bug with delta time calculation after stopping/starting animation, but it's easy to fix.

这篇关于CCDirecter用UIView / nib替换场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆