使用Java FXGL构建太空游侠游戏

本文是一篇使用FXGL在JavaFX上构建名为"Space Ranger"的简单游戏的教程。FXGL是基于JavaFX的游戏引擎,为开发跨平台游戏提供了便利。文章介绍了FXGL的基本概念,下载方法,以及游戏开发过程,包括游戏对象/实体的创建,输入处理,游戏逻辑,物理和更新。教程以创建一个简单的太空防御游戏为例,展示了如何使用FXGL实现游戏开发。
摘要由CSDN通过智能技术生成

In this simple FXGL tutorial, we will develop a game called “Space Ranger”.

在这个简单的FXGL教程中,我们将开发一个名为“ Space Ranger”的游戏。

什么是FXGL? (What is FXGL?)

FXGL is a game engine built on top JavaFX, which is a GUI toolkit for desktop, mobile, and embedded systems.

FXGL是基于顶级JavaFX构建的游戏引擎,JavaFX是用于台式机,移动和嵌入式系统的GUI工具包。

为什么在JavaFX上使用FXGL? (Why use FXGL over JavaFX?)

On its own, JavaFX provides general-purpose rendering and UI capabilities. On top of it, FXGL brings real-world game development techniques and tools, making it easy to develop cross-platform games.

JavaFX本身提供了通用的呈现和UI功能。 最重要的是,FXGL带来了现实世界的游戏开发技术和工具,使开发跨平台游戏变得容易。

如何下载FXGL JAR? (How to Download FXGL JARs?)

FXGL can be downloaded as a Maven or Gradle dependency. For example, Maven coordinates are as follows, which can be used with Java 11+.

FXGL可以作为Maven或Gradle依赖项下载。 例如,Maven坐标如下,可与Java 11+一起使用。


<dependency>
    <groupId>com.github.almasb</groupId>
    <artifactId>fxgl</artifactId>
    <version>11.8</version>
</dependency>

If you get stuck at any point, you can find the full source code link at the end of this tutorial.

如果您有任何困难,可以在本教程的结尾找到完整的源代码链接。

太空游侠游戏 (Space Rangers Game)

Our game idea is relatively simple. We have a bunch of enemies who are trying to get to our base and we have a single base protector — the player. Given this is an introduction tutorial, we will not use any assets, such as images, sounds, and other external resources. When completed, the game will look like this:

我们的游戏思路比较简单。 我们有一堆试图进入我们基地的敌人,而我们只有一个基地保护者-玩家。 鉴于这是一个入门教程,因此我们将不使用任何资产,例如图像,声音和其他外部资源。 完成后,游戏将如下所示:

Let us begin!

让我们开始吧!

所需进口 (Required Imports)

First, let’s take care of all the imports, so we can focus on the code aspect of the tutorial. For simplicity, all of the code will be in a single file, however you may wish to place each class in its own file.

首先,让我们处理所有导入,因此我们可以专注于本教程的代码方面。 为了简单起见,所有代码都在一个文件中,但是您可能希望将每个类放在自己的文件中。

Create a file SpaceRangerApp.jav

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值