Question
I am new to Godot and game development in general, however I am a software engineer with a few years of experience.
I am creating a game that is similar to Paradox games, i.e. there is a world map on a 2D plane and you can zoom in and out of it and click on regions. While I have been able to use a Sprite2D
object to display the map and then use my mouse’s cursor position to determine where I clicked, it seems hacky. From my research, TileMapLayer
is the most appropriate object to do this. However, I can’t for the life of me to get it to work. Maybe it’s because I’m using the UI, if there is a programmatic way to create a TileSet
that would be awesome.
Here is the relevant info:
Structure
I tested out a lot of different structures (see here) but this is the most simple.
Control
- TileMapLayer
Control
For simplicity’s sake, Control
has an attached script control.gd
. It’s anchors are set to Full Rect
and it has a script which just does this:
func _ready() -> void:
var map: TileMapLayer = $TileMapLayer
map.show()
TileMapLayer
This is probably where I went wrong and I assume it has something to do with the way I created it. I created a quick, ugly map in GIMP where I make a layer for every Tile
with a unique ID in the TileSet
. I export each layer as a png into my project. Here is an example of the structure:
Then, in Godot I create a TileSet
with the inspector on TileMapLayer
. In the dialog box on the bottom, I click + -> Atlas
and import each layer as it’s own image. I automatically create the tiles for each one.
Output
A blank screen. TileMapLayer.visible == true
and it is instantiated. TileSet
is also instantiated but I can’t see any item within it on the debugging screen. Example is where I exported all layers (that’s why there is only the one Tile), but using separate layers also doesn’t work.
Other info
I test the project on the current scene (Control). Setting a main scene that instantiates the Control scene also doesn’t change it.
I set my game’s screen resolution and map dimension to 1080p while my monitor is 4k. I don’t believe this leads to an issue, because I do center my Control
, but maybe I am missing something.