gpt4 book ai didi

java - 在哪里添加 AtlasTmxMapLoader 的 atlas 属性

转载 作者:行者123 更新时间:2023-12-01 13:34:36 27 4
gpt4 key购买 nike

我正在重构我的游戏,我想使用 AltasTmxMapLoader 来提高 TiledMaps 的渲染性能。我坚持将 map 集属性添加到 map 中。例如,我需要将其放在这张 map 的哪里?

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="10" height="10" tilewidth="32" tileheight="32">
<tileset firstgid="1" name="tile2" tilewidth="32" tileheight="32">
<image source="tile2.png" width="512" height="512"/>
</tileset>
<tileset firstgid="257" name="mountain" tilewidth="32" tileheight="32">
<image source="mountain.png" width="512" height="512"/>
</tileset>
<tileset firstgid="513" name="pubdlcnt" tilewidth="32" tileheight="32">
<image source="pubdlcnt.png" width="512" height="512"/>
</tileset>
<tileset firstgid="769" name="snowWit" tilewidth="32" tileheight="32">
<image source="snowWit.png" width="512" height="512"/>
</tileset>
<tileset firstgid="1025" name="tile2" tilewidth="32" tileheight="32">
<image source="tile2.png" width="512" height="512"/>
</tileset>
<tileset firstgid="1281" name="tree+rock" tilewidth="32" tileheight="32">
<image source="tree+rock.png" width="512" height="512"/>
<tile id="129">
<properties>
<property name="blocked" value=""/>
</properties>
</tile>
<tile id="161">
<properties>
<property name="move" value=""/>
</properties>
</tile>
</tileset>
<tileset firstgid="1537" name="trees" tilewidth="32" tileheight="32">
<image source="trees.png" width="512" height="512"/>
</tileset>
<tileset firstgid="1793" name="trees2" tilewidth="32" tileheight="32">
<image source="trees2.png" width="512" height="512"/>
</tileset>
<layer name="background1" width="10" height="10">
<data encoding="base64" compression="zlib">
eJzzZ2Bg8B/FgwYDAFyQHt0=
</data>
</layer>
<layer name="background" width="10" height="10">
<data encoding="base64" compression="zlib">
eJxjYGBgmISEGfDQi5AwAx76KBSPAtxgIysEowMAMnYKLw==
</data>
</layer>
<layer name="background" width="10" height="10">
<data encoding="base64" compression="zlib">
eJybxMDAcBqIJxGgFwHxbSJoUsA1IL6OR/4XlD4KxSMBAAA87BJ0
</data>
</layer>
<layer name="foreground1" width="10" height="10">
<data encoding="base64" compression="zlib">
eJxjYCAOzCdCzTwofQyIj+NR94pIO0m1l5pgoOwFACVaBi8=
</data>
</layer>
<layer name="blocked" width="10" height="10">
<data encoding="base64" compression="zlib">
eJxrYmVgaKIiJgUQ0kOqeUMJLGKFYHQAAKpXDXA=
</data>
</layer>
</map>

我已经尝试过将其添加到 map 标签和图 block 集标签中,但这不是正确的解决方案。我已经注意到,我需要将图集放入与 tmx 文件相同的文件夹中,但我真的想知道在哪里放置标签。

<小时/>
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/util
s/GdxRuntimeException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)

Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.utils.GdxRuntimeEx
ception
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more

最佳答案

这并不像将 atlas 属性放入源那么简单。

不会使用该属性,因为 xml 中描述的图 block 根本不引用图集。

你需要的是让TiledMapPacker运行你的文件。它将预处理您的 map 、创建优化的图集文件并将属性添加到 xml 中。只有这样您才能使用 AltasTmxMapLoader 正确加载该文件。

参见my posts here了解我如何让它发挥作用的解释。

libgdx 官方发行版中的工具应该包括所有必要的东西。我用这个命令运行它:

java -classpath "gdx.jar";"gdx-natives.jar";"gdx-backend-lwjgl.jar";"gdx-backend-lwjgl-natives.jar";"gdx-tools.jar";"gdx-tiled-preprocessor.jar" com.badlogic.gdx.tiledmappacker.TiledMapPacker "processed/input" "processed/output" "--strip-unused"
<小时/>

要从代码运行它,请将其放在核心主类/项目中:

    Settings settings = new Settings();
settings.maxWidth = 2048; //modify if needed
settings.maxHeight = 2048; //modify if needed
settings.fast = true; //fast should be fine here!
//all tiles have a 1px padding. better for not getting artifacts
TiledMapPacker pack = new TiledMapPacker();
try
{
pack.processMaps(
new File(
"PATH-TO-INTPUT"),
new File(
"PATH-TO-OUTPUT"),
settings);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

关于java - 在哪里添加 AtlasTmxMapLoader 的 atlas 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375972/

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