xcode OpenGL 与 Cocos2d:选择什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9768034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:41:55  来源:igfitidea点击:

OpenGL vs Cocos2d: What to choose?

iosxcodeopengl-escocos2d-iphone

提问by Anatoliy Gatt

I understand that cocos2d it's really simple API, and that I can use it to do simple and huge 2D or even sometimes 3D games/applications. As well I understand that OpenGL it's more complicated, it's lower level API etc.

我知道 cocos2d 它是非常简单的 API,我可以用它来做简单而巨大的 2D 甚至有时是 3D 游戏/应用程序。我也知道 OpenGL 它更复杂,它是较低级别的 API 等。

Question:
What is better for implementing 2D/3D games?
Why do we need to learn OpenGL if we have simple frameworks like cocos2d?
What you can do with OpenGL that you can't do with cocos2d?

问题:
什么更适合实现 2D/3D 游戏?
如果我们有像 cocos2d 这样的简单框架,为什么还要学习 OpenGL?
OpenGL 可以做什么而 cocos2d 不能做什么?

Thanks in advance!

提前致谢!

回答by Nick Weaver

What is better for implementing 2D/3D games?

什么更适合实现 2D/3D 游戏?

  • Hard to tell, but a higher level API is always there to make things easier for you. For example you are writing a 2D shootem up. You will likely use a game loop, you will want to use sprites and make those move on the screen. You may want animations like explosions taking place. You'll end up writing your own higher level API to do those things. Cocos2D has solved those problems for you already. Any other frameworld should have solved it.
  • 很难说,但更高级别的 API 总是可以让您更轻松。例如,您正在编写 2D 射击游戏。您可能会使用游戏循环,您会想要使用精灵并使它们在屏幕上移动。您可能想要发生爆炸之类的动画。您最终将编写自己的更高级别的 API 来完成这些事情。Cocos2D 已经为你解决了这些问题。任何其他框架世界都应该解决它。

Why do we need to learn OpenGL if we have simple frameworks like cocos2d?

如果我们有像 cocos2d 这样的简单框架,为什么还要学习 OpenGL?

  • In case you like to cusomize the standard behaviour of a framework, especially the drawing part, you should get into openGL. If there is something you like to have which doesn't come out of the box you may find yourself reimplementing a base framework class. For example, look at the shaders used in Cocos2D 2.0. If you like some special blending mode, like a tinting effect, you won't get it for free. There is a colour attribute for a CCSprite but this may not be the result you're expecting. So you'll have to write your own shader and plug it into the sprite you like to be displayed in a different way.
  • 如果你喜欢自定义框架的标准行为,尤其是绘图部分,你应该进入 openGL。如果您喜欢的东西不是开箱即用的,您可能会发现自己重新实现了一个基础框架类。例如,查看 Cocos2D 2.0 中使用的着色器。如果您喜欢某种特殊的混合模式,例如着色效果,则不会免费获得。CCSprite 有一个颜色属性,但这可能不是您期望的结果。因此,您必须编写自己的着色器并将其插入您喜欢以不同方式显示的精灵中。

What you can do with OpenGL that you can't do with cocos2d?

OpenGL 可以做什么而 cocos2d 不能做什么?

  • This comparison doesn't really work out, since cocos2d facilitates opengGL for the drawing part to build up that higher level api and make your life easier as a game developer.
  • 这种比较并没有真正奏效,因为 cocos2d 为绘图部分提供了 opengGL,以构建更高级别的 api,并使您作为游戏开发人员的生活更轻松。

回答by MrTJ

Cocos2d is a wrapper around the 2D features of OpenGL (as of this: http://www.cocos2d-iphone.org/about) . Under the hood it itself uses OpenGL ES to implement its features. This is good because it means that there will be minimal performance overhead so you can start using its simpler API without having to get immersed to the definitely bigger learning path of OpenGL.

Cocos2d 是围绕 OpenGL 的 2D 功能的包装器(截至目前:http: //www.cocos2d-iphone.org/about)。在幕后,它本身使用 OpenGL ES 来实现其功能。这很好,因为这意味着将有最小的性能开销,因此您可以开始使用其更简单的 API,而不必沉浸在 OpenGL 绝对更大的学习路径中。

It has however only strong 2D support and if you plan to write later 3d games you loose all benefits of Cocos2d: why would you rewrite a 3d rendering engine with a 2d framework that under the hood uses a very strong 3d engine? You loose performance for a lot of unnecessary work.

然而,它只有强大的 2D 支持,如果您打算编写更高版本的 3d 游戏,那么您将失去 Cocos2d 的所有优势:为什么您要使用 2d 框架重写 3d 渲染引擎,而在引擎盖下使用非常强大的 3d 引擎?你会因为很多不必要的工作而失去性能。

So the simpler answer is: for 2d Cocos2d, for 3d OpenGL.

所以更简单的答案是:对于 2d Cocos2d,对于 3d OpenGL。

If you want to start OpenGL ES, this is a very good tutorial for beginners: http://iphonedevelopment.blogspot.it/2009/05/opengl-es-from-ground-up-table-of.html

如果你想开始 OpenGL ES,这是一个非常适合初学者的教程:http: //iphonedevelopment.blogspot.it/2009/05/opengl-es-from-ground-up-table-of.html