游戏交叉编译和打包
我和一些朋友想开发一款游戏。任何语言都可以。我已经用 C 编程多年,但以前从未编写过游戏。我们中的一个人对 SDL 有一点了解。这也是学习 Python+pygame 的一个很好的借口。
我们希望我们的游戏是“独立的”。我所说的独立,是指大多数用户(至少 Linux、Mac 和 Windows)无需手动下载和安装除软件包之外的任何其他内容。如果安装自动处理缺少的依赖项就可以了。如果包包含二进制文件,我们希望能够使用 Linux 的交叉编译来生成它们。
我们应该如何打包和构建项目,什么语言最适合?
Some friends and I wanted to develop a game. Any language will do. I've been programming in C for years, but never wrote a game before. One of us knows SDL a little bit. It would also be a nice excuse to learn Python+pygame.
We wish our game to be 'standalone'. By standalone, I mean most users (at least Linux, Mac and Windows) will not have to manually download and install anything else apart from a package. It is ok if the installation automatically handles missing dependencies. If the packages contain binaries, we wish to be able to generate them using cross-compilation from Linux.
How should we package and structure the project, and what language is best suited?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果您以前没有编写过游戏,我建议您从 Python 和 Pygame 开始。如果您已经是一名程序员,Python 本身很容易学习,所以这对您来说不会有太大的飞跃。
使用 Pygame,您几乎不需要花时间编写“粘合”或处理诸如窗口管理和声音设置之类的日常低级细节 - 您几乎会立即开始编写游戏逻辑,并且很快就会被
blit向左和向右。更重要的是,你可以很容易地获得运行游戏的原型,这样你就可以开始尝试机制——我在几个小时内就编写了一个简单的小型横向卷轴平台游戏。
性能
对于简单的游戏来说,Python 与 Pygame 的性能通常还不错,但“平滑滚动”游戏可能会表现出较差的性能,尤其是在 Linux 上(至少根据我的经验 - pygame.display.update()) > 实际上,在 Linux 上每帧需要 15-30 毫秒,在带有廉价英特尔显卡的 Windows 上每帧需要 4-5 毫秒,尽管这是两年前的事,而且 Linux 英特尔驱动程序最近有所改进)。此外,如果您有物理/数学重的代码 Psyco 可以为您带来巨大的加速(20% - 200%在某些情况下),尽管您将被限制在 x86 计算机上使用 32 位 Python。
一旦你解决了大部分游戏逻辑,如果性能仍然不令人满意,你可以切换到 C 和 SDL。由于您已经编写了游戏逻辑,因此您只需专注于直接处理 SDL。即使这样也应该相当容易 - Pygame 内部使用 SDL,因此翻译应该相对简单。
OpenGL
不幸的是,以上仅适用于您正在编写 2D 游戏的情况 - Pygame 基本上无法为您提供 OpenGL 的任何帮助。不过,我不建议使用 OpenGL 开始游戏编程。一开始可能很难理解,所以你会同时面临两个问题 - 首先,你试图弄清楚如何获得游戏逻辑/物理/人工智能/等。工作,然后你就很难理解 OpenGL。最终学习 OpenGL 是值得的,但不是从头开始——最好从基础知识开始,然后从那里开始。
跨平台注意事项
就跨平台问题而言 - py2exe (适用于 Windows)和 py2app (对于 Mac)允许您构建包含依赖项(包括Python 解释器和 Pygame);但是,我认为您无法从 Linux 环境构建可执行文件(可能您必须能够借用 Windows/Mac 计算机几分钟)。对于 Linux,您可能只需分发一个 .deb,其中将 Pygame 列为依赖项(如有必要,将 Psyco 列为推荐或建议)。
If you haven't programmed a game before, I'd recommend that you start with Python and Pygame. Python itself is very easy to learn if you're already a programmer, so that won't be too much of a leap for you.
With Pygame, you spend almost no time writing "glue" or dealing with mundane low-level details like window management and sound setup - you'll almost immediately be programming game logic and in no time you'll be
blit
ing left and right. What's more, it'll be very easy to get a prototype of your game running so you can start experimenting with the mechanics - I've programmed a simple little side-scrolling platformer in a matter of hours.Performance
The performance of Python with Pygame is normally decent for simple games, though "smooth-scrolling" games can show poor performance, especially on Linux (in my experience, at least -
pygame.display.update()
literally took 15-30ms per frame on Linux, and 4-5 on Windows with cheapo Intel graphics, though this was two years ago and the Linux Intel driver has improved of late). In addition, if you have physics/math-heavy code Psyco can give you huge speedups (20% - 200% in some cases), though you'll be limited to 32 bit Python on x86 computers.Once you get most of the game logic worked out, if performance is still unsatisfactory, you could switch to C and SDL. Since you've already written the game logic, you'll just have to focus on dealing directly with SDL. Even that should be fairly easy - Pygame internally uses SDL, so the translation should be relatively straightforward.
OpenGL
Unfortunately, the above is only true if you're writing a 2D game - Pygame gives you basically no help for OpenGL. However, I would not recommend starting game programming with OpenGL. It can be pretty difficult to understand at first, so you'd be presenting yourself with two problems at once - first, you're trying to figure out how to get the game logic/physics/ai/etc. working, and then you're struggling to understand OpenGL. It is worth it to learn OpenGL eventually, but not to start with - better to start with the basics and go from there.
Cross-Platform Considerations
As far as cross-platform concerns - py2exe (for Windows) and py2app (for Mac) allow you to build individual executable files that include your dependencies (including the Python interpreter and Pygame); however, I do not think you'd be able to build your executables from a Linux environment (you'd have to be able to borrow a Windows/Mac computer for a few minutes, probably). For Linux, you'd probably just distribute a .deb that lists Pygame as a Dependency (and Psyco as a Recommends or Suggests if necessary).
看看Ogre;它是火炬之光背后的引擎。它支持 Windows、Ubuntu、MacOS 和 iPhone。
您可能还想阅读Gamasutra:他们的文章、采访、深入和事后分析提供了游戏开发过程中非常有趣的见解。
Have a look at Ogre; it's the engine behind Torchlight. It supports Windows, Ubuntu, MacOS and iPhone.
You may also want to read Gamasutra: their articles, interviews, in-depth and post-mortem analisys provide a very interesting insight in the game development process.
这在很大程度上取决于您是否想要构建包括引擎在内的整个游戏,或者只是在已建立的游戏引擎上构建。尽管构建整个引擎需要更多的开销和艰苦的工作,但它会给您带来大量的经验。
现在,如果您想创建一个游戏引擎,则该工作的语言是 C++(C 也可以工作,我只是更喜欢 C++)
对于构建管理工具,我发现使用 CMake 是一个不错的选择,它可以在多个不同的平台上为您管理构建,甚至还可以创建安装程序,并安装任何所需的库。
至于库,大部分问题都可以通过 SDL 解决,使用它并不是特别愉快,但它解决了与视频(OpenGL)、窗口、输入和音频跨平台接口的麻烦。您仍然需要学习 OpenGL 才能在游戏中使用它,SDL 仅处理初始化和设置。
现在,对于使用 Python,我不会推荐它,除非您的游戏很简单(2D 或没有大量物理使用的简单 3D),因为 Python 产生的开销将开始消耗您的帧速率。对于轻量级的脚本语言来说,Lua 绝对是最好的,它简单、灵活、快速。要集成它,如果您想要一个简单的解决方案,请使用 LuaBind,但要小心!在使用它的地方要非常有选择性,因为它会完全缩短你的编译时间!
It greatly depends if you want to build a whole game including the engine, or just building upon an established game engine. Although building a whole engine includes much more overhead and hard work, it gives you tons of experience.
Now if you want to create a game engine, the language for the job is C++ (C can also work, I just like C++ better)
For a build management tool, I have found that using CMake is a great option, it manages your build for you on several different platforms, and it can also even create the installers, and install any required libraries.
As for libraries go, most of your problems will be solved by SDL, it is not particularly pleasant to work with, but It manages the headaches of cross platform interfacing with video(OpenGL), Windowing, Input and Audio. You will still need to learn OpenGL to use it in your game, SDL only handles the initialization and setup.
Now for using Python, I would not recommend it, unless your game is simple (2D, or simple 3D without heavy physics usage), because the ammount of overhead incurred by Python will start to eat into your framerate. For a light, scripting language, Lua is definitely the best, it is simple, flexible, and fast. To integrate it, if you want a simple solution, use LuaBind, but beware! Be very selective on where you use it, for it can utterly KILL your compile times!
我建议你在 QT 上开发它...QT 本身会处理大部分可移植性问题...所以你不必担心它,而且它支持大多数平台,包括手机...QT 也对游戏有很好的原生支持(图形、UI、声音控制..)
请请参阅 QT 内置应用程序
i would suggest that you develop it On QT... QT will handle most of the portability issues itself... so you don't have to worry about it, plus it supports most of the platform including mobiles... and QT also has very good native support for gaming (Graphics,UI,Sound Controls.. )
Please see application Built in QT
我猜你的游戏是3D游戏。如果是,那么您需要 OpenGL。它是 C 语言,因此您会熟悉其语法,但由于 OpenGL 是有限状态机,因此方法有点不同。有关此主题的更多信息请参见此处。
OpenGL 基本上内置在每个平台上,因此您只需要启动一个全屏窗口并让 OpenGL 处理绘图。对于交叉编译,我建议使用 C++ 的 wxWidgets 。它将允许您为在每个平台上编译的应用程序的窗口初始化编写单个代码。
wxWidgets 还有一个 python 绑定 如果你决定使用 python,在这种情况下你还需要 PyOpenGL。
I presume that your game is a 3D one. If yes, than you need OpenGL. It's C, so you'll be familiar with the syntax, but the approach is a bit different, due to the fact that OpenGL is a finite state machine. More on this topic here.
OpenGL is basically built-in on every platform, so you would only need to initiate a single full screen window and let OpenGL handle the drawing. For cross compilation, I would recommend wxWidgets that is C++. It will allow you to write a single code for the window initialization of your application that compiles on each platform.
wxWidgets also have a python binding if you decide to go for python in which case you would also need PyOpenGL.
对于休闲游戏我推荐 Flash
For casual gaming I would recommend Flash