Create your own class that extends from inputs
Do all your input processing in _unhandled_input(event):
send input to rest of the engine for processing
Add as a Sigleton
Guestures.gd
class_name Guestures extends Node
class LongPress extends InputEventAction:
const DELAY_TIME = 0.5
var position = Vector2(0,0)
var timer = Timer.new()
func _init():
timer.connect("timeout", self, "_on_long_press")
func start(event):
position = event.position
if timer.is_stopped(): timer.start(DELAY_TIME)
func is_valid():
return position != Vector2(0,0)
func cancel():
position = Vector2(0,0)
timer.stop()
func as_text():
return "GuestureLongPress : position=" + str(position)
func _on_long_press():
pressed = true
Input.parse_input_event(self)
var touches = Array()
var drags = Array()
var long_press = LongPress.new()
func _unhandled_input(event):
if event is InputEventScreenTouch:
if event.pressed:
touches[event.index] = event
if event.index == 0:
long_press.start(event)
else:
touches.erase(event.index)
drags.erase(event.index)
if long_press.is_valid():
long_press.pressed = false
Input.parse_input_event(long_press)
long_press.cancel()
elif event is InputEventScreenDrag:
drags[event.index] = event
long_press.cancel()
Input.parse_input_event(event)
sends the event to all nodes to be handled so you could do on any node
func _input(event):
if event is Guesture.Longpress:
if event.is_pressed():
foo()
To add more Gestures just add more classes like for e.g
class Pinch extends InputEventAction:
another thing to note is if you want syntax highlighting for your gestures then add them to their own files and use class_name
instead of class
for e.g. class_name InputEventScreenLongpress extends InputEventAction