I have the following code that prints the location of a tile in the tilemap when the mouse hovers over it, and it works fine for what is in the viewport.
extends Node2D
func _ready():
VisualServer.set_default_clear_color(Color(0.3,0.3,0.3,1.0))
func _process(_delta):
#if Input.is_mouse_button_pressed(BUTTON_LEFT):
var mousePos = get_viewport().get_mouse_position()
var loc = $CaveTileMap.world_to_map(mousePos)
var cell = $CaveTileMap.get_cell(loc.x, loc.y)
if cell != -1:
print($CaveTileMap.tile_set.tile_get_name(cell), " ", loc.x, " ", loc.y)
The problem comes when my player moves and the camera scrolls the map, it only ever returns the tile coords of the view port... i.e. the top left of the screen is always 0,0 and bottom right is 19,10.
How do I get it to report the tile coordinate relative to the whole map?