Giter Site home page Giter Site logo

godot-tiled-importer's Introduction

Tiled Map Importer

This is a plugin for Godot Engine to import TileMaps and TileSets from the Tiled Map Editor.

Note: This is compatible only with Godot 3.0 or later. For Godot 2.x, use the 1.x branch.

ko-fi If you like what I do, please consider buying me a coffee on Ko-fi.

The last 2 images are from the game Indirection on Steam. You can check it out here!

Installation

Simply download it from Godot Asset Library: https://godotengine.org/asset-library/asset/158.

Alternatively, download or clone this repository and copy the contents of the addons folder to your own project's addons folder.

Then enable the plugin on the Project Settings.

Features

  • Import Tiled file as a Godot scene. Each layer in Tiled is a TileMap in Godot.
  • Import TileSets from Tiled standalone tileset files.
  • Both .tmx (XML) and .json formats for maps.
  • Both .tsx (XML) and .json formats for tilesets.
  • Support for Base64 encoded map.
  • Support for layer compression, both zlib and gzip are supported.
  • Object templates.
  • Orthogonal, isometric, staggered, and hexagonal maps.
  • Import visibility and opacity from layers.
  • Import collision/occluder/navigation shapes (based on Tiled object type).
  • Support for one-way collision shapes.
  • Custom import options, such as whether to enable UV clip.
  • Support for image layers.
  • Support for object layers, which are imported as StaticBody2D, Area2D or LightOccluder2D for shapes (depending on the type property) and as Sprite for tiles.
  • Support for group layers, which are imported as Node2Ds.
  • Custom properties for maps, layers, tilesets, and objects are imported as metadata. Custom properties on tiles can be imported into the TileSet resource.
  • Map background imported as a parallax background (so it's virtually infinite)
  • Support for post-import script.
  • Support for tile animations.
  • Custom materials for tilesets
  • Set Z index per layer (via the z_index custom property).

Usage (once the plugin is enabled)

  1. Place your maps inside your project.
  2. Watch Godot import it automatically.

The map file can be used as if it were a scene, but you can not edit it in Godot. If you need to make changes, create an inherited scene or instance the map in another scene.

Whenever you make a change to the map in Tiled, Godot will reimport the scene and update it in the editor if it's open.

If the file can't be imported, an error message will be generated in the output. Please check the output if you are having an issue.

Note that if you are using external tilesets, they will also be imported, which may increase the final export size of your project. To mitigate that, you can exclude those files from the export or put them in a folder alongside a .gdignore file so they are not even imported.

Note: If you have other .json files in your project, this plugin will try to import them and fail. There's an option in the Project Settings to disable the JSON format and avoid this. If you need to use JSON format for Tiled files, consider putting the non-Tiled JSON files in a folder alongside a .gdignore file so Godot won't try to import them.

Find more useage information on the Wiki.

Caveats on Tiled maps

  • Godot TileSets only have one navigation and one occluder per tile, so the last found will overwrite the others.

  • There's no Ellipse shape in Godot. If you use it as a collision object, it will be converted to a capsule shape, which may be imprecise. However, if the Tiled ellipse is a perfect circle, a CircleShape2D will be used instead.

  • Set the type of the object to area, navigation or occluder to use it as such.

  • Set the type of the object to one-way to mark it as a one-way shape in Godot (both on tile and on object layers).

  • Objects in object layer cannot be set as navigation.

  • Only polygons can be used as occluder/navigation. For those, you can make a polygon or polyline in Tiled. Rectangles will be converted to polygons, but ellipses are not accepted.

  • Occluder shapes are set as closed if a polygon is used and as open if it is a polyline.

  • For isometric maps, the collision shapes and objects likely will be out of place, because Tiled applies the isometric transform to everything.

Import system caveats

  • If you are embedding images, changing them won't trigger a reimport of the map.

  • If you are using external tile sets in Tiled, changing the tile set won't trigger a reimport.

  • Essentially, every change you do that doesn't directly change the source Tiled map, won't trigger the automatic reimport. In this case you can manually reimport if needed.

Options (Maps and TileSets)

There are two import presets: Default and Pixel Art. The difference is that the Pixel Art preset don't use any flag for the texture, disabling filter, mipmaps, and repeat.

Because it overrides the image flags, it also embed internal images by default, otherwise it won't make a difference. If you want to avoid that, use the Default preset and import your images without flags.

Note that you can set a different default preset on Godot.

In the Project Settings, there's a Tiled Importer section with settings related to this plugin. Currently it's only used so you can disable the JSON format if needed.

Custom Properties

Default: On

Whether or not to save the custom properties as metadata in the nodes and resources.

Tile Metadata

Default: Off

Whether or not to save the tile metadata into the TileSet resource. It will be set as a dictionary named tile_meta where the key is the tile global id (the same id used in the Godot TileMap).

Uv Clip (Map only)

Default: On

Enable the Clip Uv (Filter Clip on Sprites) to avoid image bleeding on tiles.

Image Flags

Default: Mipmaps, Repeat, Filter (Note: this is set as Texture.FLAGS_DEFAULT)

The image flags to apply to all imported TileSet images. This will only work if images are embedded, otherwise they will use the flags from their own import settings.

Collision Layer (Map only)

Default: 1

The collision layer for the maps and objects imported. If you need custom layers for each object, consider using a post-import script.

Embed Internal Images

Default: Off

By default, if an image is inside the project, it won't be reimported. If this option is enabled, the images will be embedded into the imported scene. This is useful if you need to use the image somewhere else with different import settings.

Save Tiled Properties

Default: Off

Save the regular properties from Tiled inside the objects as metadata. They will be placed alongside the custom properties.

Note: Not all properties from the file are saved, only the ones you can see on Tiled interface.

Add Background (Map only)

Default: On

Add a parallax background to make the map background color from Tiled. This option is irrelevant if there's no map background color defined in the Tiled map.

Apply Offset (Tileset only)

Default Off

Tilesets on Tiled use the bottom-left as origin, while Godot uses top-left. This option applies an offset to the tileset to make this consistent. It is applied by default on maps to sort out the positioning of everything, but for Tileset importing this is optional.

Post-import script

Default: None

The selected script will have it's post_import(scene) method run. This enables you to change the generated scene automatically upon each reimport.

The post_import method will receive the built scene (or TileSet) and must return the changed scene (or TileSet).

License

MIT License. Copyright (c) 2018 George Marques.

godot-tiled-importer's People

Contributors

aaronsnoswell avatar cmfcmf avatar elouataoui avatar giraugh avatar jakes1403 avatar jonathlela avatar matt-c-lane avatar olivergs avatar olsonjeffery avatar radicaled avatar rosshadden avatar shinaka avatar sirramesq avatar sleepprogger avatar tubeliar avatar univeous avatar vnen avatar wildos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

godot-tiled-importer's Issues

Importing map causes some tiles to be blank or other tiles

When I Import a simple map, some of the tiles are replaced with other tiles or left blank.

Looking at the tileset in the godot editor it seems all the tiles are created properly, but the actual tileset ends up with random tiles on the map or a empty tile.

tiled view

in-godot

noob need help with custom properties

how do i access custom properties?
first time i added properties to the tile itself, which i think is not suposed to work right now
next i removed those and added properties to a collision shape which i think should work?
what object do i access to get the metadata

Can import .tmx file into godot:

returns, this error msg:
res://addons/vnen.tiled_importer/tiled_map.gd:169 - Invalid operands 'int' and 'String' in operator '+'

Collisions masks are not always imported

Hello,

I've defined collisions masks in my Tiled file.
When there are defined as rectangles or circles, they are imported (circles are transformed to capsules, as you warn in your ReadMe).
But when they are either polygon or polyline, they are not imported properly. I tried to draw them in clockwise order, as you mention it in the documentation.

I've made a super simple project for showing this:
http://www.fileconvoy.com/dfl.php?id=gce45a38560766ea09999213823bd8b15150eb6388
(password is godotgodot)
In the project above, collisions defined with rectangles are imported in Godot (horizontal and vertical road tiles).

You can see a screenshot of a collision not exported here:
http://tof.canardpc.com/view/2300dbe5-c12d-422a-912d-007cd6702fcc.jpg
(this is a screenshot of the tmx file provided in the archive above).

Thank you!

Can't import with post-import script (Misleading error messages).

Post-import contains only "return string"
In output of editor next error appears:
res://addons/vnen.tiled_importer/tiled_importer_plugin.gd:101 - Invalid call. Nonexistent function 'new' in base 'GDScript'.
Using Godot stable 2.1.3. Stopped to work unexpectedly (before certain moment with post-import script was possible)

Can't import Tilemaps that have TileSets with different sizes.

I have a Tiled map whose tile width / height is 32x32.

However, I have a tileset that's a collection of images, with some images larger than 32x32 -- 64x64 or higher[0]. The add-on won't import them because of this check:

if (width and height) and (image.get_width() != width or image.get_height() != height):

I've been exporting to .tmx format, if that helps.

[0] The kind of Tileset that gets generated when you do this: File -> New -> New Tileset, select "Type: Collection of Images". This kind of Tileset lets you mix and match without having to rely on a single huge tilesheet.

Relative image loading doesn't work if not nested in .tmx file in directory hierarchy.

Due to some work in progress I had a directory structure like this:

+ game-root
   - campaigns
     - test_campaign              # Original test files
       - test_campaign.tmx
       - test_campaign.tsx
       - test_campaign.png
     - assets                           # "Production" assets, mid-organization of directory structure
       - test_campaign
          - new_campaign_assets.tsx    # Used by test_campaign.tmx
          - new_campaign_assets.png   # Used by new_campaign_assets.tsx

However, the importer can't find "new_campaign_assets.png" because it's checking /game-root/campaigns/test_campaign. I think this is because options.basedir is, and when a .tsx and its .png file are side-by-side there's no absolute path involved, just a relative one.

ability to specify object shapes that come over as arbitrary Area2Ds

Right now the importer supports collision geometry, occluders, etc based on annotation in the object properties...

Would it be possible to extend this to allow bringing over something as an Area2D (instead of e.g. a StaticBody2D)? This, combined with the custom property annotations which convert to metadata, would allow some powerful automated functionality w/i games (e.g. creating teleporters to connect tiled maps).

I imagine this would be pretty straightforward to implement and I'm open to putting together a PR, I just haven't bothered to look at the plugin code, yet. Any pointers would be appreciated.

As it is, I think I could implement this in my own project via scraping and recreating an area2D at the position of a staticbody2d and removing the child beneath it and adding that collision shape to the newly created Area2D instead. But it would seem cleaner and less work at run time to handle this during the import (also wouldn't have to move over metadata).

Custom property doesn't appear as metadata

Hello,

I'm trying to import a map with an object which contain a custom property:

image

I check the checkbox is check in the import window

image

But my test script I put on the objects layer don't see anything:

	print("Metadata list:")
	for i in get_children():
		print(i.get_meta_list())

Here the output i have :

	Metadata list:
	[]

I use the 2.1.3 version of Godot (the Steam one) and the last version of Tiled version 1.0.0

What am I doing wrong ?

Post_import function: scene is not affected by my modification

Hello,

I'm trying to automatically add a player to the scene.

here the code of my post_import script:

extends Node

var player = preload("res://Scene/Player.tscn")

func _ready():
	pass

func post_import(scene):
	var p = player.instance()
	scene.add_child(p)
	return scene

The scene don't seem to be affected by my change since the player isn't in the scene.
But if I return "p", the player instance, the scene imported is an copy of the player scene which mean the code is correctly executed.

I'm still new to Godot Engine, this code should work, right ?

Re-import / lag each time Godot window is re-focused (Windows)

I've been testing this plugin and it works great. I noticed that Godot does a brief pause and re-imports almost each time I focus the editor window - even though I didn't change the source files. The auto-reload is great in itself, but when it happens often the lag is just enough to annoy ๐Ÿ˜‰

I was wondering if this is a Godot-engine-related thing

Currently using v2.1.2-stable (through Steam) on Windows 10

Animated Tiles

Does this plugin support Animated Tiles? Couldn't make it work here..

polygon shape is hollow

i created a polygon shape in tiled for collision.
when i import to godot only the lines appear(show collision debugger option) and the player will fall thru them

godottiledbug

"Invalid GID" error when an object doesn't have GID set.

I was testing the addon on one of Tiled's example files (/examples/orthogonal-outside.tmx) -- the provided objects do not have a GID and their id's are arbitrary (do not point to an actual tileset) and so an import error was thrown.

I traced it to this snippet.

Wouldn't it be possible to silently ignore this warning and use any random tile for the objects? (Assuming it's necessary to have one as a placeholder).

This seems to make more sense, as setting object GIDs is, by design, optional, and this is one area where we're breaking compatibility with Tiled when it could perhaps be avoided.

What do you think?

P.S. Thanks for this addon, I must say it's really great! :D

Flipped tiles aren't imported correctly

Apparently Godot has some issues when converting float to int, making the detection not work correctly. Also, the flips are not translated correctly to the Godot system.

Not compatible with Godot 3.0b

Hi,

I'm able to edit but no longer import new Tiled maps using Godot 3, as the import functionality has radically changed.

Is there a way to import now without importing into Godot 2 and exporting the scene?

Thanks.

Concave collision not working?

Hello, the concave collision is not working on import of a tileset (godot 3.0) all are showing up convex.
Is there a way to change the shape manually? like in the .tsx is there a way to change the collision type in notepad? Or is there a way to change the shapetype in godot without losing your shape?
Thanks
ZTarget

Import issues

There's an importing error when the tsx generated in Tiled Map Editor has not-sequential id
(possible if some entryes were deleted from an existent tileset)

The situation is easy to reproduce (test on Tiled Map Editor 2017.05.02)

-Open Tiled Map Editor
-New tileset (collection of images)
-Add 3 png tiles and save
-Then select the second tile and delete it (save again)

the tsx now is formed:
the first tile tag : tile id="0"
and the second one : tile id="2"

a map created on this tileset cannot be imported
The import operation stops with a nameless error message due this not sequential id sequence.

Imported tile indices are off

Hello. It seems like the tile indices for some tiles are off, making them appear incorrect on the map. Not sure if I'm just doing something wrong or not.

Here's a simple test tilemap and tileset.

https://www.dropbox.com/s/vpjt1cqasy7nxer/godotTiledTest.zip?dl=0

Here's also a screenshot. Right's Tiled (how it should appear), and left's Godot (how it does appear).

screenie

EDIT: Ah, I forgot to include the png file, but that's okay, I think I figured it out. The plugin assumes the tile sheet source size is a multiple of the tile size when importing. So, if you have 10x10 tiles, you have to have a tilesheet that is sized to a multiple of 10x10, and not a common power of two (i.e. I can't use a 256x256 sized tilesheet).

Need help, keep getting same error when importing tilemap

Hi,

This is a great plugin and I really like it.

But after I updated the plugin today, I'm getting the following error when importing tilemap, even it's a simple tilemap with just one layer. Couldn't find any clue on what happened, can you help me? Many thanks!

SCRIPT ERROR: build: Invalid get index '1' (on base: 'Dictionary').
At: res://addons/vnen.tiled_importer/tiled_map.gd:197

Document importing features

Some people seems to have trouble importing collision shapes. Better usage information and maybe some tutorial is needed.


A little list of things there are not well documented:

  • The imported scene should not be edited directly (use inheritance or instancing)
  • How to create collision/navigation/occluder shapes (cf. #18 (comment))
  • How to set up custom properties and read the metadata in Godot
  • The possible type values for shapes and objects in an object layer
  • Post-import script usage (cf. #29)

Importer seems to not update tilesheet images when re-importing.

I made some pretty big edits to my tilesheet in order to use Tiled's awesome Terrain Tool. Mainly lots of moving tiles around in the .png.

However, it seems like the importer didn't re-import my tilesheet image -- so the map came out looking insane. I opened up the generated .scn file in Godot, and glanced through its Tilemaps, and it was obvious it was using an old (cached?) version of the the tilesheet.

Importing the .tmx file and saving it into a new scene works perfectly fine, though.

Seeing edge artifacts in pixel art tiles; How to access/change import settings for tiled import plugin?

I'm using Godot 3.0 RC1 mono build on OSX Sierra, with godot-tiled-importer cloned from this repo in the project's addons folder

The README mentions the presets (default/pixel art). I've noticed some edge artifacts in the tilesets I'm importing (gaps between solid color tiles and lines around the tiles in general that I assume are because of filter/mipmap stuff) and i want to switch to the "pixel art" preset in order to see if that addresses the issue (I've already disabled filtering and mipmaps in the project settings).

But I can't find where this is done.. the "import" tab in the editor doesn't show anything (and the "presets" button is empty). Here is what I see in the Import tab:
screen shot 2018-01-21 at 10 23 54 am

I can't find any settings in project settings or editor settings related to the plugin. The README doesn't say exactly where these settings are, and I'm still getting used to Godot 3.0, so if you could be more explicit about where the settings are and how you can modify them, I would be grateful.

Thanks.

Support for transparent colors

Two ways that this can be done:

  1. Leave the original image like it is and use a shader to replace the pixels.
  2. Read the every pixel from the image data and replace it by a transparent one.

The first is more taxing to the game while the second is more taxing to the import process. Replacing pixels is a slow procedure (OTOH it needs to be done only when (re)importing).

Type doesn't exist ...

I tried write post_import script and and looks like:

  1. when is defined type in objecttypes.xml and values are not changed, then are properties empty
  2. object.has_meta("type") is always empty/doesn't exist.

Traverse the node tree and replace Tiled objects

func post_import(scene):

# Load scenes to instantiate and add to the level

# The scene variable contains the nodes as you see them in the editor.
# scene itself points to the top node. Its children are the tile and object layers.
for node in scene.get_children():
	# To know the type of a node, check if it is an instance of a base class
	# The addon imports tile layers as TileMap nodes and object layers as Node2D
	if node extends TileMap:
		# Process tile layers. E.g. read the ID of the individual tiles and
		# replace them with random variations, or instantiate scenes on top of them
		pass
	if node extends Node2D:
		for object in node.get_children():

			var name = object.get_name()
			print("ENTITY NAME: "+name)

			var metalist = object.get_meta_list()
			for item in metalist:
				print(str(item))
			if object.has_meta("type"):
				var type = object.get_meta("type")
				print("       TYPE: "+type)




# You must return the modified scene
return scene

Provide a sample tmx file for rerefence

I'm having a hard time understanding how to define collision shapes for my tileset. It is not explained in the readme file and I've noticed the code around line 206 deals with it but I cannot understand what it is expecting from the tmx file.

tile_meta Dictionary Not Populated with Custom Properties

Using Godot 3.0-stable and version 2.0.0 of this plugin, I can't get custom properties from Tiled into Godot. I'm using the tileset attached and importing it into Godot with the custom properties and tile metadata import options ticked. When I add a TileMap node and set the tile_set property to tilesetsheet.tsx, I can access the tile_meta dictionary from a script containing the following:

extends Node2D

func _ready():
	print($TileMap.tile_set.get_meta("tile_meta"))

Attempting to do print($TileMap.tile_set.get_meta("tile_meta")[0]) gives me Invalid get index '0' (on base: 'Dictionary')..

tilesetsheet.zip

Support for post-import script

If the user want to process information from Tiled maps, they could supply a script with functions to apply to the generated scene. This would make the import process seamless and remove the need for an extra step, while still making it flexible enough to many use cases.

Map background color

Tiled has a per-map background color setting. Since it's per-map, it can't be used as the clear color in Godot.

I wonder if there's an easy way to do this in Godot that I am missing.

Loading image from non-relative directory fails

When using assets that are not stored in the same relative folder as the tilemap, the loader appends the entire filepath to the local path, causing an error.

Example:
TMX says image source is "D:/assets/tile.png"
TMX is stored as "C:/game/levels/level1.tmx"

The importer tries to load "C:/game/levels/D:/assets/tile.png"

Support for image collection tilesets

It's possible in Tiled to make a TileSet from multiple images so each tile reference a different image. Right now the importer only recognizes single image TileSets.

Add 3.0 branch to Asset Lib

Currently, this plugin is only available in the AssetLib for Godot2. Can we get the latest version tagged for Godot3 in the AssetLib?

tile_meta doesn't exist?

Hi, I can't seem to use tile_meta to access Tiled .tsx Tile properties - even when I've enabled the import option.

I searched tile_meta, and set_meta in the repository and "tile_meta" doesn't seem to exist.

How do I access custom Tile properties now?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.