Can't get a TileMapLayer to appear at all, or is there a better approach to my problem?

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:
gimp 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.

1 Like

I think you’re misunderstanding what this node does. I made a demo for you: https://www.youtube.com/watch?v=GIfipQ_9WgE

If you want to be able to zoom in and out (and presumably select/highlight countries), you might find this easier to do in 3D. Make each country a 3D model (which could be as simple as a tesselated 2D polygon), bring those in as ArrayMesh, put a Camera3D and a light overhead, and you’ve got a map you can zoom/pan around on.

If you generate collision geometry for each country, there are calls you can use to fire a ray from the camera to where the mouse is pointing, so you can do mouse picking to select countries. You can also float sprites over them for (say) cities or armies, and give those collision too. That gives you everything you need to have a map with fine-grained mouse picking.