TIlemaps with Lights included

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CyttilDalionzo
:warning: Old Version Published before Godot 3 was released.

Hi all,

So I have a scene that contains my tileset, which has some Sprites with a Light2D attached to them. However, when I export the tileset and try to use it, the lights have mysteriously vanished (though the rest works fine).

Is it simply not possible to include lights in a tileset like this? Or am I doing something wrong/forgetting something? (If it isn’t possible, how else could I get the proper lights with their corresponding tiles?)

:bust_in_silhouette: Reply From: Zylann

Tiles don’t contain light information (actually, they cannot contain every single feature in the engine, it would be a mess): https://github.com/godotengine/godot/blob/master/scene/resources/tile_set.h#L42

You have to add the lights afterwards, with something like this:

var cell_positions = tilemap.get_used_cells()
for pos in cell_positions:
	var tile_id = tilemap.get_cellv(pos)
	var tile_name = tilemap.get_tileset().tile_get_name(tile_id)
	if tile_name == "my_light_tile":
		# Create your light here...

Yeah, because tiles also contained Occluder information, I thought they must also contain Light information, but I guess I was wrong. Thanks, your provided code works!

CyttilDalionzo | 2016-09-26 07:56

It can be improved btw, I just wrote it as an example :wink:

Zylann | 2016-09-26 12:36

Yeah, I ended up just checking the number of the tile that was being placed, and instantiating a new light if that number corresponded with a light-tile (because I have the numbers hard-coded). Works fast and smoothly.

CyttilDalionzo | 2016-09-26 20:07