godot-demo-projects/visual_script/multitouch_view/TouchHelper.gd

21 lines
769 B
GDScript3
Raw Normal View History

extends Node
2017-12-07 03:34:10 +01:00
# This will track the position of every pointer in its public `state` property, which is a
2020-08-04 01:20:11 +02:00
# Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
2017-12-07 03:34:10 +01:00
# It works by listening to input events not handled by other means.
# It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
# It can be conveniently setup as a singleton.
var state = {}
func _unhandled_input(event):
if event is InputEventScreenTouch:
if event.pressed: # Down.
2020-08-04 01:20:11 +02:00
state[event.index] = event.position
else: # Up.
2020-08-04 01:20:11 +02:00
state.erase(event.index)
2020-03-14 08:07:16 +01:00
get_tree().set_input_as_handled()
elif event is InputEventScreenDrag: # Movement.
2020-08-04 01:20:11 +02:00
state[event.index] = event.position
2020-03-14 08:07:16 +01:00
get_tree().set_input_as_handled()