Skip to content

pablogila/TileMapDual_godot_node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TileMapDual Godot Node

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.

Advantages

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

Installation and usage

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,atlas_id=0): Fill a given world cell and update the corresponding dual tiles, from a given atlas with atlas_id (0 by default).
  • erase_tile(world_cell,atlas_id=0): 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 the Update 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 tilesets

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.

Multiple atlases

You can use multiple atlases in the same tileset. To change them in-game, make sure you call the fill_tile and erase_tile methods described above with the desired atlas_id, which is 0 by default.

Why?

This release simplifies the implementation of a dual-grid system by introducing a simple custom node that runs automatically and in-editor, making it easy to integrate into your own projects.

Previous implementations of a dual-grid tileset system in Godot, mainly by jess::codes and GlitchedInOrbit, were not automatic and required extensive manual configuration (at the time of writing). These implementations also 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.

Plus, you can use multiple atlases in the same tileset.

Oh, and also... You can use isometric tilesets!

To-do

  • Animations I guess
  • I am personally not interested in hex grids right now, but I am open to pull requests!

License

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!

References

Feedback

Please feel free to contact me to provide feedback, suggestions, or improvements to this project :D