Created
April 21, 2020 23:58
-
-
Save eduardonunesp/725ae44b1ac8302dee3b0f079a7ad905 to your computer and use it in GitHub Desktop.
Swipe Detector Godot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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