在 OpenGL ES 视图和 UIKit 视图控制器之间切换

发布于 2024-08-22 04:24:14 字数 485 浏览 9 评论 0原文

这是我的问题。

我正在使用 OpenGL ES 在 iPhone 上开发游戏。我开始使用 Xcode 模板 OpenGL ES 应用程序进行开发,并使用一个 EAGLView 等。

我的菜单视图和游戏视图使用相同的 OGL 视图,但现在我想添加分数排名,因此我需要一个键盘和一个文本字段来写入名称,以及一些标签或表格视图来显示排名。

更新:嗯,我认为最好的解决方案是将我当前的 glView 与另一个 UIKit 视图一起使用,我将在其中放置分数排名并进行切换。

我有 Apress 的书Beginning iPhone Development,并且我遵循有关多个视图的章节。我注意到在两个 UIViewController 之间切换,但是当我要在游戏中进行更改时... glView 不是 UIViewController,它是 UIView,所以我迷路了。

谁能帮我解决这个问题吗? :-(

非常感谢。

this is my question.

I'm developing a game on iPhone with OpenGL ES. I began my development using the Xcode template OpenGL ES Application, with one EAGLView, etc.

My menu view and game view use the same OGL view but now I want to add score ranking so I need a keyboard and a text field to write name, and some labels or a table view to show ranking.

UPDATE: well, I think that the best solution is to have my current glView with another UIKit View where I will put the score ranking and do the switching.

I have the Apress book Beginning iPhone Development and I follow the chapter about multiple views. I take the point of switching between two UIViewController but when I'm going to make changes in my game... glView is not a UIViewController, it's a UIView, so I'm lost.

Can anyone help me with this? :-(

Thank you very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2024-08-29 04:24:14

嗯,我想我解决了这个问题,所以我把解决方案分享给你。

我从书中的多个视图示例开始:三个 xib(主窗口和我们切换的两个视图)、应用程序。 delegate,每个视图有两个视图控制器和一个在视图之间切换的根视图控制器。

我将 EAGLView 类和渲染器添加到该项目中,并将 EAGLView 上的 initWithCoder 方法更改为 initWithFrame:

//- (id) initWithCoder:(NSCoder*)coder
- (id)initWithFrame:(CGRect)frame
{    
    if ((self = [super initWithFrame:frame])) {
    // The same we had.

然后,在我的根视图控制器中,当我点击按钮时,我添加了一个 IBAction:

- (IBAction)drawEAGLView:(id)sender {
    CGRect rect = [[UIScreen mainScreen] applicationFrame];
    glView = [[EAGLView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
    self.view = glView;
    [glView startAnimation];
}

就这样。非常简单而且效果很好。也许它需要一些优化,但这是一个很好的起点。

所以,我现在可以做我的分数排名了:D

Well, I think I solved the problem, so I share the solution with you.

I started from the multiple views example from the book: three xib (main window and two views we switch), the app. delegate, two view controller for each view and a root view controller which switch between our views.

I added the EAGLView class and renderer to this project and changed the initWithCoder method on EAGLView to initWithFrame:

//- (id) initWithCoder:(NSCoder*)coder
- (id)initWithFrame:(CGRect)frame
{    
    if ((self = [super initWithFrame:frame])) {
    // The same we had.

Then, in my root view controller I have added an IBAction when I tap a button:

- (IBAction)drawEAGLView:(id)sender {
    CGRect rect = [[UIScreen mainScreen] applicationFrame];
    glView = [[EAGLView alloc] initWithFrame:CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)];
    self.view = glView;
    [glView startAnimation];
}

And that's all. Very simple and it works well. Maybe it needs some optimization but this is a good start point.

So, I can make now my score ranking :D

百思不得你姐 2024-08-29 04:24:14

您只需将普通视图控制器推到 OpenGL 视图(控制器)顶部即可显示分数排名对话框。例如使用 presentModalViewController:animated:

You can simply push a normal viewcontroller on top of the OpenGL view(controller) to show a dialog for the score ranking. For example with presentModalViewController:animated:.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文