【问题标题】:Where to add the atlas property for AtlasTmxMapLoader在哪里添加 AtlasTmxMapLoader 的 atlas 属性
【发布时间】:2014-01-27 08:24:13
【问题描述】:

我正在重构我的游戏,我想使用AltasTmxMapLoader 来提高我的TiledMaps 的渲染性能。我坚持将 atlas 属性添加到地图中。例如,我需要把它放在这张地图的什么地方?

<?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>

我已经尝试过将它添加到地图标签和瓦片集标签,但这不是正确的解决方案。我已经注意到,我需要将地图集与 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

【问题讨论】:

    标签: java xml libgdx assets tiled


    【解决方案1】:

    这不像只是将 atlas 属性放到源中那么容易。

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

    您需要让TiledMapPacker 运行您的文件。它将预处理您的地图,创建优化的地图集文件并将属性添加到 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"
    

    要从代码中运行它,请将其放在 core-main 类/项目中:

        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();
        }
    

    【讨论】:

    • 这会导致字幕。添加了堆栈。我移动到扩展文件夹并输入命令。在此之前,我在同一目录中添加了已处理/输入和输出的文件夹,并添加了一些 tmx 文件,包括。将图块集放入输入文件夹
    • 谢谢我解决了,但不是通过命令行解决的。我将它添加到 coreprojekt 中,这样它就可以开始了。我将编辑您的帖子并将其作为正确答案进行检查。谢谢。顺便说一句,这确实破坏了地图。还不知道为什么。在 badlogicgames 论坛上发布
    【解决方案2】:

    我最近在 libGDX 1.5.5 中遇到了这个问题,并尝试使用 TiledMapPacker 类。

    但是,according to the official forums,自 2015 年 2 月起不再支持此功能。

    使用 libGDX 1.5.5,我通过以下步骤在我的项目中使用地图集/打包平铺地图:

    要么创建一个新项目,要么确保 Tools 扩展已添加到您的项目中(我选择了一个新项目)。我也在为 Android 和桌面开发。

    在 Android 资产目录中,我创建了一个原始和打包目录,并将精灵 PNG 和 Tiled .tmx 文件放入。

    在 .tmx 文件中,添加名为 atlas 的地图级别属性,并将其设置为对项目有意义的文件名。稍后您将使用它。

    如果您在 Android Studio(或您的编辑器)中打开 .tmx 文件,您会在文件顶部找到类似以下内容:

    <map version="1.0" orientation="isometric" renderorder="left-up" width="5" height="5" tilewidth="128" tileheight="64" nextobjectid="1">
     <properties>
      <property name="atlas" value="tiledexampletiles.atlas"/>
     </properties>
     <tileset firstgid="1" name="City - Roads" tilewidth="133" tileheight="123">
    

    在桌面项目中,您需要在 DesktopLauncher.java 文件中导入以下内容:

    import com.badlogic.gdx.tools.texturepacker.TexturePacker;
    

    现在使用TexturePacker.process() 实际生成您的图集。

    public class DesktopLauncher {
        public static void main (String[] arg) {
            TexturePacker.Settings settings = new TexturePacker.Settings();
            // If your images are numbered, but not for animation, you'll probably need this.
            settings.useIndexes = false;
    
            TexturePacker.process(settings, "raw", "packed", "tiledexampletiles.atlas");
    
            LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    
            new LwjglApplication(new LibGDXToolsApp(), config);
        }
    }
    

    运行桌面应用程序,它应该会在 Android 资产目录中生成必要的 atlas 文件和 png。

    如果您需要配置应用程序,the steps to configure an application in Android Studio 1.1.x 是:

    1. 选择运行 > 编辑配置
    2. 点击左上角的+,选择应用。
    3. 填充名称(我通常使用 Desktop),将 Main 类指向您的 DesktopLauncher(例如 com.jamesrskemp.libgdxToolsApp.desktop.DesktopLauncher),将您的工作目录设置为您的 android 资产目录(C:\path\to\LibGDXToolsApp\android\assets),最后将您的“使用类路径修改为desktop

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-31
      • 2015-02-11
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多