用于游戏开发的图形和音乐工具
游戏 开发

> 
> 要在三天内打造一个可玩的游戏，你需要一些快速而稳定的好工具。
> 
> 
> 


![](/data/attachment/album/201812/31/001708cq67g0u9kkzz7j6z.png)


在十月初，我们的俱乐部马歇尔大学的 [Geeks and Gadgets](http://mugeeks.org/) 参加了首次 [Open Jam](https://itch.io/jam/open-jam-1)，这是一个庆祝最佳开源工具的游戏 Jam。游戏 Jam 是一种活动，参与者以团队协作的方式来开发有趣的计算机游戏。Jam 一般都很短，仅有三天，并且非常累。Opensource.com 在八月下旬[发布了](https://opensource.com/article/17/8/open-jam-announcement) Open Jam 活动，足有 [45 支游戏](https://opensource.com/article/17/11/open-jam) 进入到了竞赛中。


我们的俱乐部希望在我们的项目中创建和使用开放源码软件，所以 Open Jam 自然是我们想要参与的 Jam 了。我们提交的游戏是一个实验性的游戏，名为 [Mark My Words](https://mugeeksalpha.itch.io/mark-omy-words)。我们使用了多种自由和开放源码 (FOSS) 工具来开发它；在这篇文章中，我们将讨论一些我们使用的工具和我们注意到可能有潜在阻碍的地方。


### 音频工具


#### MilkyTracker


[MilkyTracker](http://milkytracker.titandemo.org/) 是一个可用于编曲老式视频游戏中的音乐的软件包。它是一种<ruby> <a href="https://en.wikipedia.org/wiki/Music_tracker">  音乐声道器 </a> <rt>  music tracker </rt></ruby>，是一个强大的 MOD 和 XM 文件创建器，带有基于特征网格的模式编辑器。在我们的游戏中，我们使用它来编曲大多数的音乐片段。这个程序最好的地方是，它比我们其它的大多数工具消耗更少的硬盘空间和内存。虽然如此，MilkyTracker 仍然非常强大。


![](/data/attachment/album/201812/31/001709egvog5xi5x5evwd5.png)


其用户界面需要一会来习惯，这里有对一些想试用 MilkyTracker 的音乐家的一些提示：


* 转到 “Config > Misc.” ，设置编辑模式的控制风格为 “MilkyTracker”，这将给你提供几乎全部现代键盘快捷方式。
* 用 `Ctrl+Z` 撤销
* 用 `Ctrl+Y` 重做
* 用空格键切换模式编辑方式
* 用退格键删除先前的音符
* 用插入键来插入一行
* 默认情况下，一个音符将持续作用，直到它在该频道上被替换。你可以明确地结束一个音符，通过使用一个反引号（`）键来插入一个 KeyOff 音符
* 在你开始谱写乐曲前，你需要创建或查找采样。我们建议在诸如 [Freesound](https://freesound.org/) 或 [ccMixter](http://ccmixter.org/view/media/home) 这样的网站上查找采用 [Creative Commons](https://creativecommons.org/) 协议的采样，


另外，把 [MilkyTracker 文档页面](http://milkytracker.titandemo.org/documentation/) 放在手边。它含有数不清的教程和手册的链接。一个好的起点是在该项目 wiki 上的 [MilkyTracker 指南](https://github.com/milkytracker/MilkyTracker/wiki/MilkyTracker-Guide)。


#### LMMS


我们的两个音乐家使用多用途的现代音乐创建工具 [LMMS](https://lmms.io/)。它带有一个绝妙的采样和效果库，以及多种多样的灵活的插件来生成独特的声音。LMMS 的学习曲线令人吃惊的低，在某种程度上是因为其好用的节拍/低音线编辑器。


![](/data/attachment/album/201812/31/001712kuqtwq3xngwbsnib.png)


我们对于想试试 LMMS 的音乐家有一个建议：使用插件。对于 [chiptune](https://en.wikipedia.org/wiki/Chiptune)式音乐，我们推荐 [sfxr](https://github.com/grimfang4/sfxr)、[BitInvader](https://lmms.io/wiki/index.php?title=BitInvader) 和 [FreeBoy](https://lmms.io/wiki/index.php?title=FreeBoy)。对于其它风格，[ZynAddSubFX](http://zynaddsubfx.sourceforge.net/) 是一个好的选择。它配备了各种合成仪器，可以根据您的需要进行更改。


### 图形工具


#### Tiled


在开放源码游戏开发中，[Tiled](http://www.mapeditor.org/) 是一个流行的贴片地图编辑器。我们使用它为来为我们在游戏场景中组合连续的、复古式的背景。


![](/data/attachment/album/201812/31/001719tb9n5im5q27iqrr6.png)


Tiled 可以导出地图为 XML、JSON 或普通的图片。它是稳定的、跨平台的。


Tiled 的功能之一允许你在地图上定义和放置随意的游戏对象，例如硬币和提升道具，但在 jam 期间我们没有使用它。你需要做的全部是以贴片集的方式加载对象的图像，然后使用“插入平铺”来放置它们。


一般来说，对于需要一个地图编辑器的项目，Tiled 是我们所推荐的软件中一个不可或缺的部分。


#### Piskel


[Piskel](https://www.piskelapp.com/) 是一个像素艺术编辑器，它的源文件代码以 [Apache 2.0 协议](https://github.com/piskelapp/piskel/blob/master/LICENSE) 发布。在这次 Jam 期间，们的大多数的图像资源都使用 Piskel 来处理，我们当然也将在未来的工程中使用它。


在这个 Jam 期间，Piskel 极大地帮助我们的两个功能是<ruby> 洋葱皮 <rt>  Onion skin </rt></ruby>和<ruby> 精灵序列图 <rt>  spritesheet </rt></ruby>导出。


##### 洋葱皮


洋葱皮功能将使 Piskel 以虚影显示你编辑的动画的前一帧和后一帧的，像这样:


![](/data/attachment/album/201812/31/001726omjziim8caeza88r.gif)


洋葱皮是很方便的，因为它适合作为一个绘制指引和帮助你在整个动画进程中保持角色的一致形状和体积。 要启用它，只需单击屏幕右上角预览窗口下方的洋葱形图标即可。


![](/data/attachment/album/201812/31/001727a94nn339wlwwbv39.png)


##### 精灵序列图导出


Piskel 将动画导出为精灵序列图的能力也非常有用。精灵序列图是一个包含动画所有帧的光栅图像。例如，这是我们从 Piskel 导出的精灵序列图：


![](/data/attachment/album/201812/31/001727bc6ad911v3sksk16.png)


该精灵序列图包含两帧。一帧位于图像的上半部分，另一帧位于图像的下半部分。精灵序列图通过从单个文件加载整个动画，大大简化了游戏的代码。这是上面精灵序列图的动画版本：


![](/data/attachment/album/201812/31/001728izouxx71iug77o1s.gif)


##### Unpiskel.py


在 Jam 期间，我们很多次想批量转换 Piskel 文件到 PNG 文件。由于 Piskel 文件格式基于 JSON，我们写一个基于 GPLv3 协议的名为 [unpiskel.py](https://raw.githubusercontent.com/MUGeeksandGadgets/MarkMyWords/master/tools/unpiskel.py) 的 Python 小脚本来做转换。


它像这样被调用的：



```
python unpiskel.py input.piskel
```

这个脚本将从一个 Piskel 文件（这里是 `input.piskel`）中提取 PNG 数据帧和图层，并将它们各自存储。这些文件采用模式 `NAME_XX_YY.png` 命名，在这里 `NAME` 是 Piskel 文件的缩减名称，`XX` 是帧的编号，`YY` 是层的编号。


因为脚本可以从一个 shell 中调用，它可以用在整个文件列表中。



```
for f in *.piskel; do python unpiskel.py "$f"; done
```

### Python、Pygame 和 cx\_Freeze


#### Python 和 Pygame


我们使用 [Python](https://www.python.org/) 语言来制作我们的游戏。它是一个脚本语言，通常被用于文本处理和桌面应用程序开发。它也可以用于游戏开发，例如像 [Angry Drunken Dwarves](https://www.sacredchao.net/%7Epiman/angrydd/) 和 [Ren'Py](https://renpy.org/) 这样的项目所展示的。这两个项目都使用一个称为 [Pygame](https://www.Pygame.org/) 的 Python 库来显示图形和产生声音，所以我们也决定在 Open Jam 中使用这个库。


Pygame 被证明是既稳定又富有特色，并且它对我们创建的街机式游戏来说是很棒的。在低分辨率时，库的速度足够快的，但是在高分辨率时，它只用 CPU 的渲染开始变慢。这是因为 Pygame 不使用硬件加速渲染。然而，开发者可以充分利用 OpenGL 基础设施的优势。


如果你正在寻找一个好的 2D 游戏编程库，Pygame 是值得密切注意的一个。它的网站有 [一个好的教程](http://Pygame.org/docs/tut/PygameIntro.html) 可以作为起步。务必看看它！


#### cx\_Freeze


准备发行我们的游戏是有趣的。我们知道，Windows 用户不喜欢装一套 Python，并且要求他们来安装它可能很过分。除此之外，他们也可能必须安装 Pygame，在 Windows 上，这不是一个简单的工作。


很显然：我们必须放置我们的游戏到一个更方便的格式中。很多其他的 Open Jam 参与者使用专有的游戏引擎 Unity，它能够使他们的游戏在网页浏览器中来玩。这使得它们非常方便地来玩。便利性是一个我们的游戏中根本不存在的东西。但是，感谢生机勃勃的 Python 生态系统，我们有选择。已有的工具可以帮助 Python 程序员将他们的游戏做成 Windows 上的发布版本。我们考虑过的两个工具是 [cx\_Freeze](https://anthony-tuininga.github.io/cx_Freeze/) 和 [Pygame2exe](https://Pygame.org/wiki/Pygame2exe)（它使用 [py2exe](http://www.py2exe.org/)）。我们最终决定用 cx\_Freeze，因为它是跨平台的。


在 cx\_Freeze 中，你可以把一个单脚本游戏打包成发布版本，只要在 shell 中运行一个命令，像这样：



```
cxfreeze main.py --target-dir dist
```

`cxfreeze` 的这个调用将把你的脚本（这里是 `main.py`）和在你系统上的 Python 解释器捆绑到到 `dist` 目录。一旦完成，你需要做的是手动复制你的游戏的数据文件到 `dist` 目录。你将看到，`dist` 目录包含一个可以运行来开始你的游戏的可执行文件。


这里有使用 cx\_Freeze 的更复杂的方法，允许你自动地复制数据文件，但是我们发现简单的调用 `cxfreeze` 足够满足我们的需要。感谢这个工具，我们使我们的游戏玩起来更便利一些。


### 庆祝开源


Open Jam 是庆祝开源模式的软件开发的重要活动。这是一个分析开源工具的当前状态和我们在未来工作中需求的一个机会。对于游戏开发者探求其工具的使用极限，学习未来游戏开发所必须改进的地方，游戏 Jam 或许是最好的时机。


开源工具使人们能够在不损害自由的情况下探索自己的创造力，而无需预先投入资金。虽然我们可能不会成为专业的游戏开发者，但我们仍然能够通过我们的简短的实验性游戏 [Mark My Words](https://mugeeksalpha.itch.io/mark-omy-words) 获得一点点体验。它是一个以语言学为主题的游戏，描绘了虚构的书写系统在其历史中的演变。还有很多其他不错的作品提交给了 Open Jam，它们都值得一试。 真的，[去看看](https://itch.io/jam/open-jam-1/entries)！


在本文结束前，我们想要感谢所有的 [参加俱乐部的成员](https://github.com/MUGeeksandGadgets/MarkMyWords/blob/3e1e8aed12ebe13acccf0d87b06d4f3bd124b9db/README.md#credits)，使得这次经历真正的有价值。我们也想要感谢 [Michael Clayton](https://twitter.com/mwcz)、[Jared Sprague](https://twitter.com/caramelcode) 和 [Opensource.com](https://opensource.com/) 主办 Open Jam。简直酷毙了。


现在，我们对读者提出了一些问题。你是一个 FOSS 游戏开发者吗？你选择的工具是什么？务必在下面留下一个评论！




---


via: <https://opensource.com/article/18/1/graphics-music-tools-game-dev>


作者：[Charlie Murphy](https://opensource.com/users/rsg167) 译者：[robsean](https://github.com/robsean) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
In early October, our club, [Geeks and Gadgets](http://mugeeks.org/) from Marshall University, participated in the inaugural [Open Jam](https://itch.io/jam/open-jam-1), a game jam that celebrated the best of open source tools. Game jams are events where participants work as teams to develop computer games for fun. Jams tend to be very short—only three days long—and very exhausting. Opensource.com [announced](https://opensource.com/article/17/8/open-jam-announcement) Open Jam in late August, and more than [three dozen games](https://opensource.com/article/17/11/open-jam) were entered into the competition.


Our club likes to create and use open source software in our projects, so Open Jam was naturally the jam we wanted to participate in. Our submission was an experimental game called [Mark My Words](https://mugeeksalpha.itch.io/mark-omy-words). We used a variety of free and open source (FOSS) tools to develop it; in this article we'll discuss some of the tools we used and potential stumbling blocks to be aware of.

## Audio tools

### MilkyTracker

[MilkyTracker](http://milkytracker.titandemo.org/) is one of the best software packages available for composing old-style video game music. It is an example of a [music tracker](https://en.wikipedia.org/wiki/Music_tracker), a powerful MOD and XM file creator with a characteristic grid-based pattern editor. We used it to compose most of the musical pieces in our game. One of the great things about this program is that it consumed much less disk space and RAM than most of our other tools. Even so, MilkyTracker is still extremely powerful.

![MilkyTracker](https://opensource.com/sites/default/files/u128651/mtracker.png)

opensource.com

The user interface took a while to get used to, so here are some pointers for any musician who wants to try out MilkyTracker:

- Go to Config > Misc. and set the edit mode control style to "MilkyTracker." This will give you modern keyboard shortcuts for almost everything
- Undo with Ctrl+Z
- Redo with Ctrl+Y
- Toggle pattern-edit mode with the Spacebar
- Delete the previous note with the Backspace key
- Insert a row with the Insert key
- By default, a note will continue playing until it is replaced on that channel. You can end a note explicitly by inserting a KeyOff note with the backquote (`) key
- You will have to create or find samples before you can start composing. We recommend finding
[Creative Commons](https://creativecommons.org/)licensed samples at websites such as[Freesound](https://freesound.org/)or[ccMixter](http://ccmixter.org/view/media/home)

In addition, keep the [MilkyTracker documentation page](http://milkytracker.titandemo.org/documentation/) handy. It contains links to numerous tutorials and manuals. A good starting point is the [MilkyTracker Guide](https://github.com/milkytracker/MilkyTracker/wiki/MilkyTracker-Guide) on the project's wiki.

### LMMS

Two of our musicians used the versatile and modern music creation tool [LMMS](https://lmms.io/). It comes with a library of cool samples and effects, plus a variety of flexible plugins for generating unique sounds. The learning curve for LMMS was surprisingly low, in part due to the nice beat/bassline editor.

![LMMS plugins](https://opensource.com/sites/default/files/u128651/lmms_plugins.png)

opensource.com

We have one suggestion for musicians trying out LMMS: Use the plugins. For [chiptune](https://en.wikipedia.org/wiki/Chiptune)-style music, we recommend [sfxr](https://github.com/grimfang4/sfxr), [BitInvader](https://lmms.io/wiki/index.php?title=BitInvader), and [FreeBoy](https://lmms.io/wiki/index.php?title=FreeBoy). For other styles, [ZynAddSubFX](http://zynaddsubfx.sourceforge.net/) is a good choice. It comes with a wide range of synthesized instruments that can be altered however you see fit.

## Graphics tools

### Tiled

[Tiled](http://www.mapeditor.org/) is a popular tilemap editor in open source game development. We used it to assemble consistent, retro-looking backgrounds for our in-game scenes.

![One of our backgrounds in the Tiled map editor](https://opensource.com/sites/default/files/u128651/tiled.png)

opensource.com

Tiled can export maps as XML, JSON, or as flattened images. It is stable and cross-platform.

One of Tiled's features, which we did not use during the jam, allows you to define and place arbitrary game objects, such as coins and powerups, onto the map. All you have to do is load the object's graphics as a tileset, then place them using Insert Tile.

Overall, Tiled is a stellar piece of software that we recommend for any project that needs a map editor.

### Piskel

[Piskel](https://www.piskelapp.com/) is a pixel art editor whose source code is licensed under the [Apache License, Version 2.0](https://github.com/piskelapp/piskel/blob/master/LICENSE). We used Piskel for almost all our graphical assets during the jam, and we will certainly be using it in future projects as well.

Two features of Piskel that helped us immensely during the jam are onion skin and spritesheet exporting.

#### Onion skin

The onion skin feature will make Piskel show a ghostly overlay of the previous and next frames of your animation as you edit, like this:

![Two cycling screenshots showing onion skin in action](https://opensource.com/sites/default/files/u128651/onionshow.gif)

opensource.com

Onion skin is handy because it serves as a drawing guide and helps you maintain consistent shapes and volumes on your characters throughout the animation process. To enable it, just click the onion-shaped icon underneath the preview window on the top-right of the screen.

![Enabling onion skinning](https://opensource.com/sites/default/files/u128651/onionenable.png)

opensource.com

#### Spritesheet exporting

Piskel's ability to export animations as a spritesheet was also very helpful. A spritesheet is a single raster image that contains all the frames of an animation. For example, here is a spritesheet we exported from Piskel:

![One of our spritesheets](https://opensource.com/sites/default/files/u128651/sprite-artist.png)

opensource.com

The spritesheet consists of two frames. One frame is in the top half of the image and the other frame is in the bottom half of the image. Spritesheets greatly simplify a game's code by enabling an entire animation to be loaded from a single file. Here is an animated version of the above spritesheet:

![The animation represented by the spritesheet](https://opensource.com/sites/default/files/u128651/sprite-artist-anim.gif)

opensource.com

#### Unpiskel.py

There were several times during the jam when we wanted to batch convert Piskel files into PNGs. Since the Piskel file format is based on JSON, we wrote a small GPLv3-licensed Python script called [unpiskel.py](https://raw.githubusercontent.com/MUGeeksandGadgets/MarkMyWords/master/tools/unpiskel.py) to do the conversion.

It is invoked like this:

```
``````
python unpiskel.py input.piskel
```


The script will extract the PNG data frames and layers from a Piskel file (here `input.piskel`

) and store them in their own files. The files follow the pattern `NAME_XX_YY.png`

where `NAME`

is the truncated name of the Piskel file, `XX`

is the frame number, and `YY`

is the layer number.

Because the script can be invoked from a shell, it can be used on a whole list of files.

```
``````
for f in *.piskel; do python unpiskel.py "$f"; done
```


## Python, Pygame, and cx_Freeze

### Python and Pygame

We used the [Python](https://www.python.org/) language to make our game. It is a scripting language that is commonly used for text processing and desktop app development. It can also be used for game development, as projects like [Angry Drunken Dwarves](https://www.sacredchao.net/~piman/angrydd/) and [Ren'Py](https://renpy.org/) have shown. Both of these projects use a Python library called [Pygame](https://www.Pygame.org/) to display graphics and produce sound, so we decided to use this library in Open Jam, too.

Pygame turned out to be both stable and featureful, and it was great for the arcade-style game we were creating. The library's speed was fast enough at low resolutions, but its CPU-only rendering starts to slow down at higher resolutions. This is because Pygame does not use hardware-accelerated rendering. However, the infrastructure is there for developers to take full advantage of OpenGL.

If you're looking for a good 2D game programming library, Pygame is one to keep your eye on. Its website has [a good tutorial](http://Pygame.org/docs/tut/PygameIntro.html) to get started. Be sure to check it out!

### cx_Freeze

Prepping our game for distribution was interesting. We knew that Windows users were unlikely to have a Python installation, and asking them to install it would have been too much. On top of that, they would have had to also install Pygame, which is not an intuitive task on Windows.

One thing was clear: We had to put our game into a more convenient form. Many of the other Open Jam participants used the proprietary game engine Unity, which enabled their games to be played in the web browser. This made them extremely convenient to play. Convenience was one thing our game didn't have even a sliver of. But, thanks to a vibrant Python ecosystem, we had options. Tools exist to help Python programmers prepare their programs for distribution on Windows. The two that we considered were [cx_Freeze](https://anthony-tuininga.github.io/cx_Freeze/) and [Pygame2exe](https://Pygame.org/wiki/Pygame2exe) (which uses [py2exe](http://www.py2exe.org/)). We decided on cx_Freeze because it was cross-platform.

In cx_Freeze, you can pack a single-script game for distribution just by running a command like this in the shell:

```
``````
cxfreeze main.py --target-dir dist
```


This invocation of `cxfreeze`

will take your script (here `main.py`

) and the Python interpreter on your system and bundle them up into the `dist`

directory. Once this is done, all you have to do is manually copy your game's data files into the `dist`

directory. You will find that the `dist`

directory contains an executable file that can be run to start your game.

There is a more involved way to use cx_Freeze that allows you to automate the copying of data files, but we found the straightforward invocation of `cxfreeze`

to be good enough for our needs. Thanks to this tool, we made our game a little more convenient to play.

## Celebrating open source

Open Jam is important because it celebrates the open source model of software development. This is an opportunity to analyze the current state of open source tools and what we need to work on in the future. Game jams are perhaps the best time for game devs to try to push their tools to the limit, to learn what must be improved for the good of future game devs.

Open source tools enable people to explore their creativity without compromising their freedom and without investing money upfront. Although we might not become professional game developers, we were still able to get a small taste of it with our short, experimental game called [Mark My Words](https://mugeeksalpha.itch.io/mark-omy-words). It is a linguistically themed game that depicts the evolution of a fictional writing system throughout its history. There were many other delightful submissions to Open Jam, and they are all worth checking out. Really, [go look](https://itch.io/jam/open-jam-1/entries)!

Before closing, we would like to thank all the [club members who participated](https://github.com/MUGeeksandGadgets/MarkMyWords/blob/3e1e8aed12ebe13acccf0d87b06d4f3bd124b9db/README.md#credits) and made this experience truly worthwhile. We would also like to thank [Michael Clayton](https://twitter.com/mwcz), [Jared Sprague](https://twitter.com/caramelcode), and [Opensource.com](https://opensource.com/) for hosting Open Jam. It was a blast.

Now, we have some questions for readers. Are you a FOSS game developer? What are your tools of choice? Be sure to leave a comment below!

## 3 Comments