CCDirecter 用 UIView/nib 替换场景

CCDirecter replace scene with UIView / nib(CCDirecter 用 UIView/nib 替换场景)

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

问题描述

我想做的是让 Cocos2d 共享导演用 UIKit 中的 UIView 替换当前场景(可能从笔尖加载).这个想法是在 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 扩展吗?如果可能的话,我还想从故事板/笔尖加载 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 替换场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:CCDirecter 用 UIView/nib 替换场景

基础教程推荐