How to detect empty or not ocuppied tiles in a tilemap to spawn enemies or objects?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nosh247

Hi everyone, i was wondering if there was a way to iterate my cells in a tilemap and detect which cells are empty?

I have created a town and would like to spawn enemies randomly but in not occupied tiles in a tilemap.

Any help is very much appreciated!

Love the engine! being trying it out for the past 4 days and i just love it!

:bust_in_silhouette: Reply From: mateusak

You either create a singleton and an array of collision tile id’s and check it with array.has(val), which is what most games do, or you create two separate TileMaps, one for collision, the other for non-collision. Then it’s pretty simple, just spawn monsters on tiles with id -1 on the collision TileMap.

Godot have a constant for invalid cell in TileMaps.

INVALID_CELL = -1 — Returned when a cell doesn’t exist.

Emerson MX | 2018-02-15 17:00