Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swipe Detector Godot
extends Node2D
signal swipe(direction)
var swipe_start = null
var minimum_drag = 100
func _unhandled_input(event):
if event.is_action_pressed("ui_click"):
swipe_start = get_global_mouse_position()
if event.is_action_released("ui_click"):
_calculate_swipe(get_global_mouse_position())
func _calculate_swipe(swipe_end):
if swipe_start == null:
return
var swipe = swipe_end - swipe_start
if abs(swipe.x) > minimum_drag:
if swipe.x > 0:
print("SWIPE RIGHT")
emit_signal("swipe", "right")
else:
print("SWIPE LEFT")
emit_signal("swipe", "left")
if abs(swipe.y) > minimum_drag:
if swipe.y > 0:
print("SWIPE DOWN")
emit_signal("swipe", "down")
else:
print("SWIPE UP")
emit_signal("swipe", "up")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.