Last active
November 18, 2019 22:45
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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