Skip to content

Instantly share code, notes, and snippets.

@henriiquecampos
Last active November 18, 2019 22:45
Show Gist options
  • Save henriiquecampos/c15b3a926105ec31fd1926dc99053d87 to your computer and use it in GitHub Desktop.
Save henriiquecampos/c15b3a926105ec31fd1926dc99053d87 to your computer and use it in GitHub Desktop.
A Tilemap that maps Nodes to cell positions, allowing to access them based on their cell
extends TileMap
var tiles = {}
func _ready():
update_tiles()
func update_tiles():
for tile in get_tree().get_nodes_in_group("tile"):
if not tile.has_method("get_global_position"):
continue
var cell = world_to_map(to_local(tile.global_position))
set_tile(cell, tile)
func set_tile(cell, node):
tiles[cell] = node
func get_tile(cell):
var node = null
if tiles.has(cell):
node = tiles[cell]
return node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment