java 如何用Java编写简单的游戏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1020509/
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
How to program simple games with Java
提问by Sajee
If I wanted create a Jeopardy or Wheel of Fortune type (TV/board game genre) desktop game, what's the best way to learn how to do so in Java? I'm not trying to create anything complicated like Quake or Spore but something orders of magnitude less complex.
如果我想创建一个 Jeopardy 或 Wheel of Fortune 类型(电视/棋盘游戏类型)桌面游戏,那么在 Java 中学习如何做到这一点的最佳方法是什么?我不是要创建像 Quake 或 Spore 那样复杂的东西,而是要创建一些数量级不那么复杂的东西。
I imagine I would need to render a game board/setting, simple effects and sounds. What Java tools, libraries are recommended for this?
我想我需要渲染一个游戏板/设置、简单的效果和声音。为此推荐哪些 Java 工具、库?
Alternatively, if Python, Ruby or some other environment is more appropriate for this type of game development, please recommend.
或者,如果Python、Ruby或其他一些环境更适合此类游戏开发,请推荐。
Thanks.
谢谢。
回答by Zifre
For Java, I highly suggest the book "Developing Games in Java" by David Brackeen. It's is a reallygreat book that teaches you everything from simple tile based games to complex, scripted first person shooters.
对于 Java,我强烈推荐David Brackeen所著的“ Developing Games in Java”一书。这是一个真正伟大的书,从最简单的瓷砖游戏,复杂的脚本第一人称射击游戏教你的一切。
However, Python is also really nice for simple games using Pygame.
然而,Python 对于使用Pygame 的简单游戏也非常好。
回答by karlipoppins
check out jmonkeyengine. It has a big community, lots of tutorials, and is you can create small projects really fast.
查看jmonkeyengine。它有一个很大的社区,很多教程,而且你可以非常快速地创建小项目。
回答by Thomas Zoechling
I think Processingwould be a good choice for you.
Processing comes with a lot of classes that simplify development of multimedia applications. (2D & 3D graphics, sound, ...).
It also comes with an integrated development environment.
The syntax is inspired by Java but simplified.
IIRC it also allows deployment as applets or standalone programs - so you users don't need anything besides Java.
Wikipediahas a good introduction.
我认为Processing对你来说是一个不错的选择。
Processing 附带了许多简化多媒体应用程序开发的类。(2D 和 3D 图形、声音……)。
它还带有一个集成的开发环境。
语法受 Java 启发,但经过简化。IIRC 它还允许部署为小程序或独立程序 - 因此您的用户除了 Java 之外不需要任何东西。
维基百科有很好的介绍。
回答by cdmckay
I've nearly completed a game written in Java along with a friend and here's what we used:
我和一个朋友几乎完成了一个用 Java 编写的游戏,这是我们使用的:
Graphics:
图形:
- Started with Java2D but it was too slow so we moved to LWJGLand wrote a simple OpenGL 2D renderer using examples from the net. However, about three-quarters of the way through the project, we discovered that there were existing engines like Slick2Dand PulpCore.
- 从 Java2D 开始,但它太慢了,所以我们转移到LWJGL并使用网络上的示例编写了一个简单的 OpenGL 2D 渲染器。然而,在项目进行到大约四分之三的时候,我们发现已经存在像Slick2D和PulpCore这样的引擎。
Music:
音乐:
- Ended up going with JavaZoom's Vorbis SPI and JOrbis for Ogg Vorbis music after we found out we'd need to pay royalties if we used MP3 via JLayer (also from JavaZoom). Their libraries are LGPL, so you can link them in your project without having to release your game's source.
- Also used BasicPlayer (by JavaZoom) to play the music.
- 在我们发现如果我们通过 JLayer(也来自 JavaZoom)使用 MP3 需要支付版税后,我们最终选择了JavaZoom的 Vorbis SPI 和 JOrbis 用于 Ogg Vorbis 音乐。它们的库是 LGPL,因此您可以将它们链接到您的项目中,而无需发布您的游戏源。
- 还使用 BasicPlayer(由 JavaZoom 开发)播放音乐。
Sound:
声音:
- For sound effects, we used WAV files and plain old Java Sound. Java Sound is a pretty awful API.
- 对于音效,我们使用了 WAV 文件和普通的 Java Sound。Java Sound 是一个非常糟糕的 API。
Miscellaenous:
杂项:
- We used JDOM for our XML config files. It's a very nice library to use for XML, except it's a little old (no generics).
- 我们将 JDOM 用于我们的 XML 配置文件。这是一个非常好的用于 XML 的库,除了它有点旧(没有泛型)。
As for everything else, we just used the Java standard libraries. For information on writing game loops (which is probably the most confusing part) check out this discussionabout them.
至于其他一切,我们只是使用了 Java 标准库。有关编写游戏循环的信息(这可能是最令人困惑的部分),请查看有关它们的讨论。
If this is your first game, I recommend starting with a framework like PulpCore or Slick2D.
如果这是您的第一款游戏,我建议您从 PulpCore 或 Slick2D 之类的框架开始。
回答by Jherico
Until the Sun Java App store is up and running, Flash is really the popular mechanism for creating an distributing basic games.
在 Sun Java App Store 启动并运行之前,Flash 确实是创建分发基本游戏的流行机制。

