iPhone 棋盘游戏:OpenGL ES 还是 CoreGraphics? [英] iPhone board game: OpenGL ES or CoreGraphics?

查看:16
本文介绍了iPhone 棋盘游戏:OpenGL ES 还是 CoreGraphics?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为 iPhone 编写一个棋盘游戏(类似于跳棋).OpenGL ES 或 CoreGraphics 会是更好的选择吗?App Store 上大多数此类游戏都使用什么?

I want to program a board game (similar to checkers) for the iPhone. Would OpenGL ES or CoreGraphics be a better option? What do most games of this type on the App Store use?

推荐答案

实际上,在这种情况下,我建议的是 Core Animation,甚至只是 UIViews 本身.如果您通过 Core Graphics 在单个视图中直接绘制所有元素,然后为每个动画帧刷新该视图,您将获得可怕的性能.

Actually, what I'd suggest in this case is Core Animation or even just UIViews themselves. If you do direct drawing of all of your elements in a single view via Core Graphics, then refresh that view for every animation frame, you'll get horrible performance.

我建议将游戏板的离散元素(棋子、计数器、棋盘方格等)绘制为单独的 UIView 或 CALayer,然后为这些层或视图设置动画.UIViews 并没有比 CALayers 重太多,它们在幕后使用 Core Animation 来做简单的移动、缩放或淡入淡出的动画.他们还可以响应触摸事件.如果您想构建更跨平台(Mac 和 iPhone)的游戏,或者如果您需要制作更复杂的动画,CALayers 非常有用.

I'd suggest drawing the discrete elements of the game board (pieces, counters, board squares, etc.) as individual UIViews or CALayers, then animating those layers or views around. UIViews aren't too much heavier than CALayers, and they use Core Animation behind the scenes to do simple movement, scaling, or fading animations. They can also respond to touch events. CALayers are useful if you want to build a more cross-platform (Mac and iPhone) game, or if you need to do more complex animations.

对于 2-D 游戏,我会暂缓使用 OpenGL,直到您完全确定无法从 Core Animation 中获得您想要的那种性能.OpenGL 的代码没有那么优雅.

For a 2-D game, I'd hold off on OpenGL until you were absolutely sure that you couldn't get the kind of performance you want from Core Animation. OpenGL is a lot less elegant to code for.

关于如何使用 Core Animation 制作棋盘游戏的一个很好的例子,A​​pple 提供了 GeekGameBoard 示例代码.虽然它是一个 Mac 应用程序,但 Core Animation 代码可以直接翻译到 iPhone.

For a good example of how to do a board game using Core Animation, Apple has provided the GeekGameBoard sample code. Although it's a Mac application, the Core Animation code can translate right across to the iPhone.

这篇关于iPhone 棋盘游戏:OpenGL ES 还是 CoreGraphics?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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