How do you load a tmx/xml file in javafx?

后端 未结 1 1325
暗喜
暗喜 2021-01-27 09:58

What is the most efficient way to add a tile map in a JavaFX program?

The program that I use for creating tile maps is called \"Tiled\", and the saved files are in .tmx

1条回答
  •  情歌与酒
    2021-01-27 10:26

    Use the Eppleton JavaFX TileEngine (unfortunately this link is now dead: similar content is still hosted on javageeks: Beware link comes with annoying add popup).

    Update: Unfortunately the eppleton blog entry previously linked, which contained detailed information on creating a tile engine using JavaFX, no longer exists.

    I have no idea how to import the file, still.

    You will not find at present some library somebody has created and packaged as a binary jar you can just add to your class path to get a generic tile reader for JavaFX.

    Loading a TileMap is a complex task. The Eppleton link I provided provides detailed information on how to implement that task as well as source code snippets. The Eppleton information is the best available on TileMaps in JavaFX. By using the Eppleton engine you can reduce the effort involved to load a TileMap to:

    TileMap map = TileMapReader.readMapFromFile(fileURL);
    

    There is a github repository for the Eppleton game engine. I tried it and most of the code is there but some of the dependencies for the project did not resolve for me so I was unable to build it. You can contact the author for assistance in resolving dependencies or you can fork the engine and patch it to allow it to work for you. The approach the engine seems to take is to use an abstraction for canvas so that the engine can render into different canvas types (JavaFX canvas being one of these). But I couldn't find the code for the abstraction layer.

    The core code for the time map reader is in the de.eppleton.fx2d.tileengine package. You can fork the code and study it to understand how in detail how the tile map reader works and how you might adapt it for your game.

    0 讨论(0)
提交回复
热议问题