Introducing TileMapDual: a simple, automatic and straightforward custom TileMapLayer
node for Godot that provides a real-time, in-editor and in-game dual-grid tileset system, for both square and isometric grids.
This dual-grid system, as explained by Oskar Stålberg, reduces the number of tiles required from 47 to just 15 (yes, fifteen!!), rocketing your dev journey!
Not only that, but if your tiles are symmetrical, you can get away with drawing only 6 (six!) tiles and then generating the 15-tile-tilesets used by TileMapDual, thanks to tools like Wang Tile Set Creator.
Using a dual-grid system has the following advantages:
- Only 15 tiles are required for autotiling, instead of 47
- The tiles can have perfectly rounded corners
- The tiles align to the world grid
Just copy the TileMapDual.gd
script to your project to start using the new custom node.
You have to create a regular TileMapLayer
with your own 2x2 tileset, following the standard godot tileset.
You just need to quickly sketch your level with the fully-filled tile, indicated here:
Then, create a TileMapDual
node and assign the TileMapLayer
to it. Just click the Update in Editor
checkbox, and the dual grid will be automatically configured and generated in real-time.
Any change in the TileMapLayer
will be updated by simply clicking the checkbox again!
You can also freeze the tileset by activating the Freeze
checkbox, to avoid accidental updates, both in-editor and in-game.
You can modify the dual tileset in-game by calling the following methods. An example is included in the custom CursorDual
node, based on Jess's implementation.
fill_tile(world_cell)
: Fill a given world cell and update the corresponding dual tiles.erase_tile(world_cell)
: Erase a given world cell and update the corresponding dual tiles.
Two more public methods are available, although you may not need them in most cases:
update_tile(world_cell)
: Update the displayed tiles around a given world cell. This is the fastest method to update specific cells.update_tileset()
: Update the entire tileset, offsetting itself by half a cell, and updating all tiles at once. This is what happens when you click theUpdate in Editor
button.
To achieve the best performance, only the fully-filled tile used for sketching in the World grid is used for autotiling in the TileMapDual
. This approach allows the World tileset to be used for other purposes, such as having an extended tileset with rocks, etc.
Isometric tilemaps are now compatible with the TileMapDual
node.
You heard that right, isometric, as in 'isometric'. It works automatically, out of the box. Isometric tilemaps! yayyyy!
To use isometric tilemaps, you only need to follow an isometric-ed version of the standard godot tileset template that we previously used for square tilemaps. Here it is:
That's it. Just 15 tiles for isometric autotiling. I love it.
Previous implementations of a dual-grid tileset system in Godot by GlitchedInOrbit and jess::codes used an inverted version of the standard 16-tile template (although Jess's tileset is provided as an example in this repo). This is a potential source of headaches, and this release corrects said inversion.
This release also implements modern TileMapLayers instead of the deprecated TileMap node.
Most importantly, this release simplifies the process by introducing the dual grid system as a simple custom node that runs automatically and in-editor, making it easy to integrate into your own projects.
Oh, and also... You can use isometric tilesets!
- Animations I guess
- I am personally not interested in hex grids right now, but I am open to pull requests!
This project is Open Source Software, released under the MIT license. This basically means that you can do whatever you want with it. Enjoy!
I am open to pull requests, and I personally encourage you to send back any significant improvements to this code so that the Godot community continues to thrive. Thanks!
- Dual grid Twitter post by Oskar Stålberg
- 'Programming Terrain Generation' video by ThinMatrix
- 'Drawing Fewer Tiles' video by jess::codes
- jess::codes implementation in C#
- GlitchedInOrbit implementation in GDScript
- Wang Tile Set Creator
- Webtyler tool, to convert from 15-tile sets to 47-tile sets
Please feel free to contact me to provide feedback, suggestions, or improvements to this project :D