2020-02-13 00:46:27 +01:00
|
|
|
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:
|
2020-02-13 00:46:27 +01:00
|
|
|
if event.pressed: # Down.
|
2020-08-04 01:20:11 +02:00
|
|
|
state[event.index] = event.position
|
2020-02-13 00:46:27 +01:00
|
|
|
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()
|
2020-02-13 00:46:27 +01:00
|
|
|
|
|
|
|
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()
|