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

查看:59
本文介绍了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.

我建议将游戏板的离散元素(棋子,柜台,棋盘正方形等)绘制为单独的UIViews或CALayers,然后为周围的这些层或视图设置动画. UIView并不比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.

对于2D游戏,我将推迟使用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天全站免登陆