libGDX游戲開發之打包游戲(十二)
libGDX系列,游戲開發有unity3D巴拉巴拉的,為啥還用java開發?因為我是Java程式員emm…國內用libgdx比較少,多數情況需要去官網和google找資料,相互學習的可以加我聯系方式,
到此,我們已經可以開發一款簡單的游戲,下面介紹簡PC端的打包exe配置,
1、配置圖示、標題、位置等等
import com.badlogic.gdx.Files;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import top.lingkang.MyGdxGame;
/**
* @author lingkang
*/
public class DesktopLauncher {
public static void main(String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
// 視窗寬高
config.width = 600;
config.height = 800;
// 視窗顯示的位置
config.x = 0;
config.y = 0;
// 標題圖示
config.title = "無盡-飛機大戰";
config.useGL30 = true;
config.addIcon("plane/player1.png", Files.FileType.Internal);
new LwjglApplication(new MyGdxGame(), config);
}
}
效果:

使用命令的方式
gradlew desktop:dist -Dfile.encoding=utf-8
使用IDEA的插件

打成jar檔案在:desktop\build\libs下
運行

java -jar -Dfile.encoding=utf-8 -Xms256m -Xmx512m desktop-1.0.jar
2、打包EXE
官網已經提供了一個打包工具:https://github.com/libgdx/packr
可以打包到window、mac、Linux上,
下載 packr-all-4.0.0.jar,撰寫 my-packr-config.json
{
"platform": "windows64",
"jdk": "./OpenJDK8U-jdk_x64_windows_hotspot_8u302b08.zip",
"executable": "wujinApp",
"classpath": [
"desktop-1.0.jar"
],
"mainclass": "top.lingkang.desktop.DesktopLauncher",
"vmargs": [
"Xms128m","Xmx512m"
],
"minimizejre": "soft",
"output": "out-windows64"
}
其中 OpenJDK8U-jdk_x64_windows_hotspot_8u302b08.zip 我從https://mirrors.tuna.tsinghua.edu.cn/中下載的,
將 packr-all-4.0.0.jar、 my-packr-config.json OpenJDK8U-jdk_x64_windows_hotspot_8u302b08.zip desktop-1.0.jar
放到同一目錄下CMD執行:
java -jar packr-all-4.0.0.jar my-packr-config.json
注意,使用本地安裝的jdk8可能出現各種奇怪問題,不要浪費時間去解決,建議如上去下載一個未安裝使用的openjdk
等待完成,效果:

73MB大小:

能正常運行exe


我的游戲專案:
https://gitee.com/lingkang_top/plane-wars-gdx
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/332185.html
標籤:其他
