-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make use of TiledMapObjects' templates #5102
Comments
Agree but this falls under keeping the lib updated with the new versions of the tools that were already adopted. |
Any updates on this? |
As workaround, the Tiled map editor provides export options to detach objects from the templates. Example command to export the map via the 'Tiled' editor CLI: Example Gradle task to export all maps on-demand (written in Kotlin Gradle DSL): task("exportMaps") {
val inputDir = "$projectDir/src/main/tiledmaps"
val outputDir = "$projectDir/src/main/resources/maps"
inputs.dir(inputDir)
outputs.dir(outputDir)
doLast {
logger.info("Exporting 'Tiled' maps from directory $inputDir to $outputDir")
val tmxFiles = file(inputDir).listFiles { dir, name -> name.endsWith(".tmx") }
@Suppress("RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
tmxFiles.forEach {
logger.info("Exporting ${it.name}")
exec {
val outputFile = file(outputDir).absolutePath + "/" + it.name
commandLine = listOf("tiled", "--export-map", "--detach-templates", it.absolutePath, outputFile)
}
}
}
}
tasks.clean {
delete(fileTree("$projectDir/src/main/resources/maps") {
exclude(".gitignore")
})
}
tasks.processResources {
dependsOn("exportMaps")
} For reference, read https://www.mapeditor.org/2018/09/18/tiled-1-2-0-released.html for Info on the detach-preferences. Search for:
However... implementing actual object template support into the classes should not be much effort. I just didn't wanna fork it and use a custom libgdx version for my project while I wait for a pull request to be accepted and the next libgdx version to be released. |
Hi, I am making an educational resource using LibGDX, having the template functionality working without exporting with the template detached would help a lot. |
I had the same issue and an easy workaround was to extend the TmxMapLoader like this
|
Tiled 1.1 adds support for object templates. A template is saved as an external file, and you can place templates in your tilemap similar to how you place tiles from a tileset.
In the saved XML, the path to the template file is stored as an attribute of the object element.
Suppose I placed a template object and renamed it. The corresponding XML would look like this:
As you can see, many of the usual attributes (such as width, height, and type) are missing. In Tiled, I can still see these properties because it's reading them from the template file.
I think the libgdx implementation would involve
BaseTmxMapLoader.loadObject()
getting thetemplate
attribute, loading the.tx
file it points to, and filling out the missing properties using that template.As for the
.tx
file itself, its structure looks pretty simple:So it's saved the same way objects are saved in
.tmx
files.I can work around this limitation by detaching objects from their templates in my tile map, but it would be nice to be able to take full advantage of the Template functionality in Tiled.
The text was updated successfully, but these errors were encountered: