TouchHelper.gd 777 B

1234567891011121314151617181920
  1. extends Node
  2. # This will track the position of every pointer in its public `state` property, which is a
  3. # Dictionary, in which each key is a pointer index (integer) and each value its position (Vector2).
  4. # It works by listening to input events not handled by other means.
  5. # It also remaps the pointer indices coming from the OS to the lowest available to be friendlier.
  6. # It can be conveniently setup as a singleton.
  7. var state = {}
  8. func _unhandled_input(event):
  9. if event is InputEventScreenTouch:
  10. if event.pressed: # Down.
  11. state[event.index] = event.position
  12. else: # Up.
  13. state.erase(event.index)
  14. get_viewport().set_input_as_handled()
  15. elif event is InputEventScreenDrag: # Movement.
  16. state[event.index] = event.position
  17. get_viewport().set_input_as_handled()