PS:禁止拷贝形式转载,转载请以URL形式
PS:FXGL 准备写成一个系列,所以在该系列未完成前,该系列文章除了目录会被修改其他内容均可能被删改。
1.环境
- 本学习记录都是基于java 17 ,毕竟自己学习项目新版本搁着使劲用没有亿点点负担~
- maven环境本人3.6
2. hello world
-
效果
-
文件总览
- POM
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>priv.dyf.fxgl</groupId>
<artifactId>stu</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>com.github.almasb</groupId>
<artifactId>fxgl</artifactId>
<version>17.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>priv.dyf.fxgl.stu.StuApp</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- StuApp
package priv.dyf.fxgl.stu;
import com.almasb.fxgl.app.GameApplication;
import com.almasb.fxgl.app.GameSettings;
import com.almasb.fxgl.dsl.FXGL;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
/**
* @ClassName
* @Description
* @Author dyf
* @Date 2022/6/29
* @Version 1.0
*/
public class StuApp extends GameApplication {
@Override
protected void initSettings(GameSettings gameSettings) {
gameSettings.setTitle("HELLO FXGL");
gameSettings.setVersion("1.0");
}
@Override
protected void initUI() {
Text text = FXGL.getUIFactoryService().newText("HELLO FXGL", Color.BLACK, 22);
FXGL.addUINode(text,FXGL.getAppCenter().getX(),FXGL.getAppCenter().getY());
}
public static void main(String[] args) {
launch(args);
}
}
- module-info.java
open module stu {
requires com.almasb.fxgl.all;
}