如何在javafx中加载tmx / xml文件? [英] How do you load a tmx/xml file in javafx?

查看:543
本文介绍了如何在javafx中加载tmx / xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaFX程序中添加切片贴图的最有效方法是什么?

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

我用于创建切片贴图的程序称为Tiled,并且保存的文件是.tmx格式。

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

现在,问题是,如何在我的2D游戏中完全导入?我无法在网上找到有用的信息。

Now, the question is, how do I import that exactly in my 2d game? I haven't been able to find helpful information on the net.

非常感谢代码示例。

谢谢

推荐答案

使用 Eppleton JavaFX TileEngine (遗憾的是,这个链接已经死了:类似的内容仍然托管于 javageeks 当心链接附带恼人的添加弹出窗口)。

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).

更新:不幸的是,先前链接的eppleton博客条目(包含使用JavaFX创建磁贴引擎的详细信息)不再存在。

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.

你目前找不到某个人创建并打包成二进制jar的库你可以添加到你的类路径中获取JavaFX的通用磁贴阅读器。

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.

加载TileMap是一项复杂的任务。我提供的Eppleton链接提供了有关如何实现该任务以及源代码片段的详细信息。 Eppleton信息是JavaFX中TileMaps上最好的信息。通过使用Eppleton引擎,您可以减少将TileMap加载到以下所需的工作:

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

有一个 Eppleton游戏引擎的github存储库。我尝试了它,大部分代码都在那里,但项目的某些依赖项并没有为我解决,所以我无法构建它。您可以联系作者以获得有关解决依赖关系的帮助,或者您可以分叉引擎并对其进行修补以使其适合您。引擎似乎采用的方法是使用画布的抽象,以便引擎可以渲染到不同的画布类型(JavaFX画布就是其中之一)。但是我找不到抽象层的代码。

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.

时间映射阅读器的核心代码在 de.eppleton.fx2d.tileengine package 。你可以分叉代码并研究它,以便详细了解瓷砖地图阅读器的工作原理以及如何根据你的游戏进行调整。

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.

这篇关于如何在javafx中加载tmx / xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆