未加载资产(libGDX)

问题描述 投票:0回答:1

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

清单中的“ Class-Path:。处是否缺少某些内容?enter image description here

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

生成的图集文件位于指定位置。包装了纹理。到底为什么不装载东西?顺便说一句,我同时将Java版本1.8.0_241用于JDK和JRE。

编辑因此,它在Assets类中的“ TextureAtlas atlas = asset2d.get(Cn.TEXTURES);”处失败。深入了解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);
    }            
    ...                   

Desktop 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"      

Workspace 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中的第一个项目,而且我一直很困在这里,我全都不知道如何找到可能出问题的任何线索。

java eclipse gradle libgdx textures
1个回答
0
投票

我只是遇到了同样的问题,并从文件名中删除了“ .atlas”,从而解决了该问题。尽管这是文件类型,但是当我在Windows资源管理器中打开Atlas文件的属性时,该文件类型只是列为“文件”而不是Atlas。

© www.soinside.com 2019 - 2024. All rights reserved.