how to change object position to cell position? and how to change use cell name?

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

how to change this node player position to cell position, in middle cell position?

here i record the problem.

how can i change my player position to cell position like, if i want my player spawn at middle, top,down,left or right side? something like this picture
enter image description here

how can i change that that “5” to its name?
enter image description here

:bust_in_silhouette: Reply From: njamster

in this code i use 1 and 5 to change my cell. but how to change it use their name?

You don’t. :wink: set_cellv and get_cellv expect an integer.

However, you can build a dictionary for looking up the ids based on the name:

extends TileMap

var lookup = {}

func _ready():
    for tile_id in tile_set.get_tiles_ids():
        lookup[tile_set.tile_get_name(tile_id)] = tile_id

how to change this node player position to cell position, in middle cell position?

$player.global_position = map_to_world(tile_pos) + cell_size/2

thank you very much :slight_smile:

potatobanana | 2020-03-08 14:27