简体   繁体   English

适用于Linux,OSX和Windows的2D游戏编程 - C ++ / Python / OpenGL?

[英]2D Game Programming for Linux, OSX, and Windows - C++/Python/OpenGL?

A friend of mine is making the jump from graphic designer to game developer, and I have decided to work with him in my free time. 我的一个朋友正在从平面设计师跳到游戏开发者,我决定在我的空闲时间与他合作。 Neither of us have much development experience, but I am very interested in learning Python, and my friend wants to learn C++. 我们都没有太多的开发经验,但我对学习Python很感兴趣,而我的朋友想学习C ++。

I have read that C++ is the common denominator in game programming, but related questions here on SO recommend that new users avoid more difficult languages like C++. 我已经读过C ++是游戏编程的共同点,但是这里的相关问题推荐新用户避免使用像C ++这样的更难的语言。 My #1 concern is creating games that are portable between operating systems. 我的第一个问题是创建可在操作系统之间移植的游戏。 I will be using Linux to develop and play-test the game, but we would like it to run on OSX and Windows as well. 我将使用Linux开发和测试游戏,但我们希望它也可以在OSX和Windows上运行。 We have no interest in 3D game development since we don't have any experience with 3D graphics. 我们对3D游戏开发没兴趣,因为我们没有任何3D图形经验。 I would be perfectly happy with graphics equivalent to a game like VVVVVV - very simple 2D with minimal (or zero) texturing. 对于像VVVVVV这样的游戏来说,我会非常满意 - 非常简单的2D和最小(或零)纹理。

Also, is it necessary to use OpenGL for 2D graphics, or do C++/Python have some graphics libraries capable of producing game-worthy graphics? 另外,是否有必要将OpenGL用于2D图形,或者C ++ / Python是否有一些图形库能够生成有游戏价值的图形? Remember, by game-worthy I mean simple, pixelated graphics like Minecraft or VVVVVV. 请记住,通过游戏值得我的意思是简单的像素化图形,如Minecraft或VVVVVV。

We have some books on Python, C++, and OpenGL, and can dive into those if that's the right way to get started. 我们有一些关于Python,C ++和OpenGL的书籍,如果这是正确的入门方式,我们可以深入研究这些书籍。 What does everyone recommend? 每个人都推荐什么?

There's actually a handy set of libraries and modules for Python, pygame , that is extremely useful, well documented and has a ton of community support and a lot of fun games have been built with it. 实际上有一套方便的Python和pygame库和模块,非常有用,文档齐全,并且有大量的社区支持,并且已经构建了许多有趣的游戏。 And the best part, to answer part of your question, is that OpenGL is not required. 回答部分问题的最好的部分是OpenGL不是必需的。

And, because it's based on Python, it's highly portable. 并且,因为它基于Python,所以它非常便携。 Of course there are lots of challenges that come with that sort of project, but be patient and stick with it and you can learn a lot and have a lot of fun too. 当然,这类项目会带来很多挑战,但要耐心并坚持下去,你可以学到很多东西,也会有很多乐趣。

C++ is a really powerful language and there are lots of things you can do with it, and people who are experienced with C++ will say that you should learn it, and they are right because it's not going away any time soon, but you're correct in holding off a little. C ++是一种非常强大的语言,你可以用它做很多事情,对C ++有经验的人会说你应该学习它,而且它们是正确的,因为它不会很快消失,但你是正确地阻止了一点。 If you end up really enjoying developing with Python then there's nothing stopping you from picking up C++ later on and enjoying them together. 如果你最终真的很喜欢使用Python进行开发,那么就没有什么能阻止你以后选择C ++并一起享受它们了。

Above all read, practice and enjoy what you do. 最重要的是阅读,练习和享受你做的事情。

I have written several small propgrams and games with C++ and Python, and for starters I can recommend using Python until you have learned how a game is built. 我已经用C ++和Python编写了几个小的预言和游戏,对于初学者,我可以推荐使用Python,直到你学会了游戏的构建方式。

Of course, I don't know what type of games you want to create, but fory many small 2D games the efficiency of Python is enough, so you don't have to deal with the complexity of C++. 当然,我不知道你想要创建什么类型的游戏,但是对于许多小型2D游戏来说Python的效率已经足够,所以你不必处理C ++的复杂性。

The libraries I can recomend for Python are either Pygame (as we have already heard) and (even better, in my opinion) pyglet , which is a more sophisticated tool for 2D graphics (it uses OpenGL in the background). 我可以为Python推荐的库是Pygame(我们已经听过)和(在我看来更好) pyglet ,这是一个更复杂的2D图形工具(它在后台使用OpenGL)。

For 2D games written in C++, I can highly recommend ClanLib , an Open Source game engine with a large and active community, giant codebase and many examples. 对于用C ++编写的2D游戏,我强烈推荐ClanLib ,一个开源游戏引擎,拥有庞大而活跃的社区,巨大的代码库和许多示例。 I supports both Software and OpenGL rendering, and is compilable for Windows/Linux/MacOSX. 我支持软件和OpenGL渲染,并且可以编译为Windows / Linux / MacOSX。 You should definitely give it a try! 你一定要试一试!

Good luck :) 祝好运 :)

I agree with newlymintedcocoaguy something such as Pygame is the way to go in your situation. 我同意newmintedcocoaguy这样的东西,比如Pygame是你的情况。 But to awnser your second question, you can make 2D games in C++ without the use of OpenGL/DirectX. 但是为了解决你的第二个问题,你可以在不使用OpenGL / DirectX的情况下用C ++制作2D游戏。 I have done this in the past using the Windows libraries for bitmaps, RECTS etc. I assume Linux will have similiar functionality. 我过去使用Windows库来制作位图,RECTS等。我认为Linux将具有类似的功能。 Though if you want your game to be cross platform then OpenGL is probably the way to go. 虽然如果你想让你的游戏跨平台,那么OpenGL可能就是你要走的路。

i will recommend c++. 我会推荐c ++。 Many people say that its difficult, true to some extent, but you can make a good 2d game in c++, without getting into the 'difficult' part. 许多人说它在某种程度上是困难的,但是你可以用c ++制作一个好的2D游戏,而不会进入“困难”部分。 And for this you will need a library like SDL , SFML etc. Its worth your time, if you learn C++, at least you will never run in performance problem. 为此你需要一个像SDL,SFML等库。它值得你花时间,如果你学习C ++,至少你永远不会遇到性能问题。

As someone whose familiar with the "I'm new, I want to do X, what should I learn?" 作为熟悉“我是新人,我想做X的人,我该学什么?” thing, having done it quite recently, I'd say stick with Python for now. 最近做过的事情,我现在说要坚持使用Python。 As others have mentioned, there are some decent libraries like PyGame out there, and C++ is well, a little complex. 正如其他人所提到的那样,有一些像PyGame这样体面的库,C ++很好,有点复杂。

If you're learning both how to put the parts together to make a game and tangling with the language, it starts getting difficult to untangle which one is actually causing your particular problem. 如果你正在学习如何将各个部分组合在一起制作游戏与语言纠缠在一起,那么开始难以解开哪一个实际上导致了你的特定问题。 And its always possible, once you have a good feel for what you are doing to learn a new way to do it by picking up C++. 一旦你对你正在做的事情有一个良好的感觉,通过拿起C ++学习一种新的方法,它总是可能的。

For portable C++ games for beginners, I'd go with the SDL . 对于初学者的便携式C ++游戏,我会选择SDL It gives access to OpenGL, check the tutorials ! 它可以访问OpenGL,查看教程 You may probably even use it from python with the aforementioned Python-to-C binding libraries. 您可能甚至可以使用python与前面提到的Python-to-C绑定库一起使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM