mirror of
https://github.com/Relintai/broken_seals_roguelike.git
synced 2025-03-20 09:16:22 +01:00
Pinch zoom support.
This commit is contained in:
parent
ba5ef68239
commit
cc4f9af56d
@ -60,6 +60,9 @@ var nameplate : Node
|
|||||||
|
|
||||||
var init : bool = false
|
var init : bool = false
|
||||||
|
|
||||||
|
var touches : Array = Array()
|
||||||
|
var touch_zoom : bool = false
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
world = get_node(world_path) as Node2D
|
world = get_node(world_path) as Node2D
|
||||||
tile_size = get_node("/root/Main").get_tile_size()
|
tile_size = get_node("/root/Main").get_tile_size()
|
||||||
@ -185,9 +188,17 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
|
|
||||||
if event is InputEventScreenTouch:
|
if event is InputEventScreenTouch:
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
pass
|
var touch : Array = [
|
||||||
|
event.index,
|
||||||
|
event.position,
|
||||||
|
]
|
||||||
|
|
||||||
|
touches.append(touch)
|
||||||
|
|
||||||
|
if touches.size() > 1:
|
||||||
|
touch_zoom = true
|
||||||
else:
|
else:
|
||||||
if !target(event.position):
|
if !touch_zoom && !target(event.position):
|
||||||
var pos : Vector2 = world.make_canvas_position_local(event.position)
|
var pos : Vector2 = world.make_canvas_position_local(event.position)
|
||||||
|
|
||||||
pos -= transform.origin
|
pos -= transform.origin
|
||||||
@ -213,6 +224,60 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||||||
my = -1
|
my = -1
|
||||||
|
|
||||||
try_move(mx, my)
|
try_move(mx, my)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for i in range(touches.size()):
|
||||||
|
if touches[i][0] == event.index:
|
||||||
|
touches.remove(i)
|
||||||
|
break
|
||||||
|
|
||||||
|
if touch_zoom and touches.size() == 0:
|
||||||
|
touch_zoom = false
|
||||||
|
|
||||||
|
|
||||||
|
get_tree().set_input_as_handled()
|
||||||
|
|
||||||
|
if event is InputEventScreenDrag && touches.size() == 2:
|
||||||
|
if camera == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
var found : bool = false
|
||||||
|
for t in touches:
|
||||||
|
if event.index == t[0]:
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
|
||||||
|
if !found:
|
||||||
|
return
|
||||||
|
|
||||||
|
var otp : Vector2
|
||||||
|
var ttp : Vector2
|
||||||
|
|
||||||
|
if touches[0][0] == event.index:
|
||||||
|
otp = touches[1][1]
|
||||||
|
ttp = touches[0][1]
|
||||||
|
else:
|
||||||
|
otp = touches[0][1]
|
||||||
|
ttp = touches[1][1]
|
||||||
|
|
||||||
|
var olen : float = (otp - ttp).length()
|
||||||
|
var currlen : float = (otp - event.position).length()
|
||||||
|
|
||||||
|
|
||||||
|
if olen > currlen:
|
||||||
|
if camera.zoom.x >= 2:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
var l : float = event.relative.length()
|
||||||
|
camera.zoom += Vector2(l, l) * 0.01 * 72 / OS.get_screen_dpi()
|
||||||
|
else:
|
||||||
|
if camera.zoom.x <= 0.1:
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
var l : float = event.relative.length()
|
||||||
|
camera.zoom -= Vector2(l, l) * 0.01 * 72 / OS.get_screen_dpi()
|
||||||
|
|
||||||
|
|
||||||
get_tree().set_input_as_handled()
|
get_tree().set_input_as_handled()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user