I am using this approach:
http://clintbellanger.net/articles/isometric_math/
Basically, you can calculate the iso coordinates based on the screen coordinates. What I am doing is, getting the actual world position the mouse is pointing at using get_mouse_global_position() and convert this position to isometric values.
Then I translate those coordinates back to world space coordinates to actually display the sprite.
Problem is, that when the world coordinates come from a negative position, the tiles get offset by almost an entire tile amount. Here is the relevant code.
The get_coord() function returns the actual world position of the tile used to display the Sprite
func get_coord(pos : Vector2):
var t = Vector2()
var e = screen_to_iso(pos)
t = iso_to_screen(e)
print(pos)
print(e)
print(t)
return t
pass
var buildings
func screen_to_iso(pos :Vector2):
var flipx = 0
var flipy = 0
var t = Vector2()
var x_size = size/2
var y_size = size/4
t.x = int((pos.x/x_size) + (pos.y/y_size))/2
t.y = int((pos.y/y_size) - (pos.x/x_size))/2
return t
pass
func iso_to_screen(pos : Vector2):
var t = Vector2()
var x_size = size/2
var y_size = size/4
t = Vector2((pos.x-pos.y)*x_size, (pos.x+pos.y)*y_size)
return t
pass
I can't seem to figure out a way