2014-01-27 14 views
0

我重構我的遊戲我想使用AltasTmxMapLoader來提高我的TiledMaps的渲染性能。我堅持將地圖集屬性添加到地圖中。例如,我需要把它放在這張地圖上?在哪裏添加AtlasTmxMapLoader的地圖集屬性

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

我已經嘗試過將它添加到地圖標記和tileset標記,但這不是正確的解決方案。我已經注意到,我需要將圖集放入與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 

回答

1

它不像只是把地圖集屬性源一樣簡單。

不會使用該屬性,因爲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" 

從代碼中把這個核心,主類/項目的內部運行:

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

這會導致刪除。添加了堆棧。我移到了擴展文件夾並輸入了命令。爲此,我添加了文件夾處理/輸入和輸出在同一目錄中,並打包一些tmx文件。將tilesets放入輸入文件夾 – BennX

+0

謝謝我解決了它,但沒有通過命令行。我將它添加到coreprojekt中,所以它開始了。生病編輯您的文章並將其作爲正確答案進行檢查。謝謝。 順便說一句,這確實是毀了地圖。不知道爲什麼。張貼在badlogicgames論壇上 – BennX

0

最近,我通過這個問題與去libGDX 1.5.5並嘗試使用TiledMapPacker類。

但是,according to the official forums,截至2015年2月,不再支持。

隨着libGDX 1.5.5,我通過以下步驟去用一本地圖冊/包裝的小塊映射在我的項目:

可以創建一個新的項目或確保該工具擴展已經被添加到你的項目(我選擇了一個新項目)。我也在爲Android和桌面開發。

在Android資產目錄中,我創建了一個原始和打包的目錄,並放置了sprite 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. 選擇Run>編輯配置
  2. 點擊左上角並選擇應用程序的+
  3. 填充名稱(我通常使用桌面),將Main類指向您的DesktopLauncher(例如com.jamesrskemp.libgdxToolsApp.desktop.DesktopLauncher),將您的工作目錄設置爲您的Android資產目錄(C:\path\to\LibGDXToolsApp\android\assets),最後將您的'使用mod的類路徑'設置爲desktop