gpt4 book ai didi

java - LibGDX - TexturePacker2 不生成/打包图像

转载 作者:太空狗 更新时间:2023-10-29 16:17:51 24 4
gpt4 key购买 nike

我目前正在阅读一本关于 LibGDX 游戏开发的书 - Learning LigbGDX Game Development .在书中,我们使用 TexturePacker2 生成一个 .png 和 .pack 文件,将六个纹理打包成一个纹理图集。我完全按照代码进行操作,但它不会在目标文件夹中生成任何内容。这是我的桌面项目文件夹中的代码:

package com.packtpub.libgdx.canyonbunny;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;

public class Main {
private static boolean rebuildAtlas = true;
private static boolean drawDebugOutline = false;

public static void main (String[] args) {
if (rebuildAtlas) {
Settings settings = new Settings();
settings.maxWidth = 1024;
settings.maxHeight = 1024;
settings.debug = drawDebugOutline;
TexturePacker2.process(settings, "assets-raw/images", "../CanyonBunny-android/assets/images", "canyonbunny.pack");
TexturePacker2.process(settings, "assets-raw/images-ui", "../CanyonBunny-android/assets/images", "canyonbunny-ui.pack");
rebuildAtlas = false;
}

LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "CanyonBunny";
cfg.useGL20 = false;
cfg.width = 800;
cfg.height = 480;

new LwjglApplication(new CanyonBunnyMain(), cfg);
}
}

但是当我运行它时,我的 CanyonBunny-android/assets/images 文件夹中没有生成任何内容。加载纹理的唯一方法是下载本书的源代码并将已生成的 .png 和 .pack 文件夹放在正确的文件夹中。我完全按照这本书做的,所以我不确定问题出在哪里。我收到它正在生成 1024x1024 纹理图集的日志消息,因此正在执行代码。有什么我想念的吗?

这是我启动应用程序时控制台显示的内容(使用已生成的文件)

Packing.........
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny.png
Packing......
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny-ui.png
game.Assets: # of assets loaded: 2
game.Assets: asset: images/canyonbunny.pack
game.Assets: asset: images/canyonbunny.png

没有已经生成的文件:

Packing.........
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny.png
Packing......
Writing 1024x1024: ../CanyonBunny-android/assets/images/canyonbunny-ui.png
game.Assets: Couldn't load asset 'images/canyonbunny.pack'
com.badlogic.gdx.utils.GdxRuntimeException: File not found: images/canyonbunny.pack (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:127)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:97)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:59)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:103)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:92)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:399)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:314)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:337)
at game.Assets.init(Assets.java:38)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:17)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)
game.Assets: # of assets loaded: 0
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:111)
Caused by: java.lang.NullPointerException
at com.badlogic.gdx.utils.ObjectMap.get(ObjectMap.java:278)
at com.badlogic.gdx.assets.AssetManager.get(AssetManager.java:103)
at game.Assets.init(Assets.java:45)
at com.packtpub.libgdx.canyonbunny.CanyonBunnyMain.create(CanyonBunnyMain.java:17)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:125)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:108)

最佳答案

  • 使用文件资源管理器(而非 eclipse)检查文件是否实际创建在正确的文件夹中。
    如果找不到,请先尝试搜索并使其出现在正确的文件夹中。

    日志提示正在生成文件,我想应该是。

  • 但是,eclipse 无法识别新生成的文件。在使用它们之前,您必须在 eclipse 项目文件夹中点击刷新。
    首先检查它是否有效。

  • 现在您将无法在每次运行时打包它们。我有同样的问题,所以我创建了一个不同的项目(用作工具)来打包(并自动化许多其他小事情)。每当我更改 Assets 时,我都会在测试前运行该工具一次。

希望这对您有所帮助。
祝你好运。

关于java - LibGDX - TexturePacker2 不生成/打包图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22544678/

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