Fix InputEvent coordinate space conversion.

This commit is contained in:
Relintai 2020-07-16 00:30:06 +02:00
parent c0388997c1
commit 0b0fceb2b9

View File

@ -140,9 +140,7 @@ func _unhandled_input(event: InputEvent) -> void:
camera.zoom -= Vector2(event.factor, event.factor) * 0.01 camera.zoom -= Vector2(event.factor, event.factor) * 0.01
elif event.button_index == BUTTON_LEFT and event.device != -1: elif event.button_index == BUTTON_LEFT and event.device != -1:
if event.pressed: if event.pressed:
#https://github.com/godotengine/godot/issues/32222 var pos : Vector2 = world.make_canvas_position_local(event.position)
var pos = event.position - get_viewport_transform().origin
pos *= camera.zoom
pos -= transform.origin pos -= transform.origin
@ -180,9 +178,7 @@ func _unhandled_input(event: InputEvent) -> void:
if event is InputEventScreenTouch and event.pressed: if event is InputEventScreenTouch and event.pressed:
if !target(event.position): if !target(event.position):
#https://github.com/godotengine/godot/issues/32222 var pos : Vector2 = world.make_canvas_position_local(event.position)
var pos = event.position - get_viewport_transform().origin
pos *= camera.zoom
pos -= transform.origin pos -= transform.origin
@ -271,9 +267,7 @@ func set_tile_position(pos : Vector2) -> void:
transform.origin = pos * tile_size + Vector2(tile_size / 2, tile_size / 2) transform.origin = pos * tile_size + Vector2(tile_size / 2, tile_size / 2)
func target(position : Vector2) -> bool: func target(position : Vector2) -> bool:
#https://github.com/godotengine/godot/issues/32222 position = world.make_canvas_position_local(position)
position = position - get_viewport_transform().origin
position *= camera.zoom
var pos : Vector2 = world.pixel_to_tile(position.x, position.y) var pos : Vector2 = world.pixel_to_tile(position.x, position.y)
var enemy : Entity = world.get_enemy_at_tile(pos.x, pos.y) var enemy : Entity = world.get_enemy_at_tile(pos.x, pos.y)