gpt4 book ai didi

java - 资源未加载(libGDX)

转载 作者:行者123 更新时间:2023-12-01 18:03:33 25 4
gpt4 key购买 nike

所以我在Eclipse(gradle项目)中基于libGDX制作了一个小型桌面应用程序。在 Eclipse 中完美运行。当我导出为“可运行的 JAR 文件”(选中将所需的库打包到生成的 JAR 中)时,我收到警告:“Fat Jar 导出:找不到 'D:Project TI Helper/core/的类路径条目” bin/默认/”。

Class-Path: .”处的 list 中是否缺少某些内容?
enter image description here

我不知道这是关于什么的。但 JAR 肯定无法运行。所以我尝试命令提示符并执行“gradle Desktop:dist --stacktrace”。然后生成的 JAR 文件似乎没有任何错误或警告。因此,我转到 .../desktop/build/libs/并尝试使用“java -jar Desktop-1.0.jar”运行它,纹理打包程序开始打包,但最终失败控制台中的消息。 enter image description here

生成的图集文件位于指定位置。纹理很丰富。到底为什么它不加载这些东西?顺便说一句,我对 JDK 和 JRE 使用 Java 版本 1.8.0_241

编辑
因此,它在“TextureAtlas atlas = assets2d.get(Cn.TEXTURES);”处的 Assets 类中失败。深入了解 AssetManager

    public synchronized <T> T get (String fileName) {
Class<T> type = assetTypes.get(fileName);
if (type == null) throw new GdxRuntimeException("Asset not loaded: " + fileName);
...

所以看来提供的字符串没有指向我的图集文件。 Cn.TEXTURES 定义为“../desktop/assets/atlas/textures.atlas”。这就提出了一个问题:如何编写路径?

DesktopLauncher.java

public class DesktopLauncher
{
public static boolean rebuildAtlas = true;
public static boolean drawDebugOutline = true;

public static void main (String[] arg)
{
// Build Texture Atlases
if (rebuildAtlas) {
Settings settings = new Settings();
settings.maxWidth = 2048;
settings.maxHeight = 2048;
settings.pot = false;
settings.combineSubdirectories = true;

// Pack images in "textures" folder
TexturePacker.process("assets/textures", "assets/atlas", "textures.atlas");

}

LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();

cfg.title = "TI Helper";
cfg.useGL30 = false;
cfg.width = Cn.RESOLUTION_WIDTH;
cfg.height = Cn.RESOLUTION_HEIGHT;
cfg.fullscreen = true;

new LwjglApplication(new TIHelper(), cfg);

}
}

Assets .java

public class Assets implements Disposable, AssetErrorListener
{
public static final String TAG = Assets.class.getName();
public static final Assets instance = new Assets();

// Asset managers
public AssetManager assets2d;

public AssetDeco assetDeco;
public AssetFonts fonts;
public AssetMisc assetMisc;

// General fonts
public static Font not16, not20, not24, dig16;

// Singelton: prevent installation from other classes
private Assets() {}

public void init ()
{

// Init 2D graphics manager
init2DAssetManager();

TextureAtlas atlas = assets2d.get(Cn.TEXTURES);
// Cn.TEXTURES == String TEXTURES = "../desktop/assets/atlas/textures.atlas";

// Create game resource objects
fonts = new AssetFonts();
assetDeco = new AssetDeco(atlas);
assetMisc = new AssetMisc(atlas);

// Create fonts
not16 = new Font(Assets.instance.fonts.notalot_16);
not20 = new Font(Assets.instance.fonts.notalot_20);
not24 = new Font(Assets.instance.fonts.notalot_24);
dig16 = new Font(Assets.instance.fonts.digits_16);
}

private void init2DAssetManager()
{
// Create the manager
assets2d = new AssetManager();
// Set asset manager error handler
assets2d.setErrorListener(this);
// Load texture atlas
assets2d.load(Cn.TEXTURES, TextureAtlas.class);
// Start loading assets and wait until finished
assets2d.finishLoading();

// Prompt output
Gdx.app.debug(TAG, "# of assets loaded: " + assets2d.getAssetNames().size);
for (String a : assets2d.getAssetNames())
Gdx.app.debug(TAG, "asset: " + a);
}

@Override
public void dispose ()
{
assets2d.dispose();
}

public void error (String filename, Class<?> type, Throwable throwable) {
Gdx.app.error(TAG, "Couldn't load asset '" + filename + "'", (Exception)throwable);
}
...

桌面 build.gradle

apply plugin: "java"

sourceCompatibility = 1.8
sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = ["../desktop/assets"]

project.ext.mainClassName = "com.ti.desktop.DesktopLauncher"
project.ext.assetsDir = new File("../desktop/assets")

task run(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
}

task debug(dependsOn: classes, type: JavaExec) {
main = project.mainClassName
classpath = sourceSets.main.runtimeClasspath
standardInput = System.in
workingDir = project.assetsDir
ignoreExitValue = true
debug = true
}

task dist(type: Jar) {
manifest {
attributes 'Main-Class': project.mainClassName
}
dependsOn configurations.runtimeClasspath
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}

dist.dependsOn classes

eclipse.project.name = appName + "-desktop"

工作区build.gradle

buildscript {


repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {


}
}

allprojects {
apply plugin: "eclipse"

version = '1.0'
ext {
appName = "ti-helper"
gdxVersion = '1.9.10'
roboVMVersion = '2.3.8'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}

repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}

project(":desktop") {
apply plugin: "java-library"


dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers-desktop:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers-platform:$gdxVersion:natives-desktop"

}
}

project(":core") {
apply plugin: "java-library"


dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
api "com.badlogicgames.gdx:gdx-controllers:$gdxVersion"
api "net.dermetfan.libgdx-utils:libgdx-utils:0.13.4"
api "net.dermetfan.libgdx-utils:libgdx-utils-box2d:0.13.4"

}
}

如果有人可以帮助我,我将不胜感激。这是我在 libGDX 中的第一个项目,我被困在这里,我完全不知道如何找到任何可能出错的线索。

最佳答案

我刚刚遇到了同样的问题,并从文件名中删除“.atlas”修复了它。尽管这是文件类型,但当我在 Windows 资源管理器中打开图集文件的属性时,文件类型只是列为"file"而不是图集。

关于java - 资源未加载(libGDX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60594358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com