swipe detector
use `_input` and add position propertys.
bendn 2022-08-18
parent fe51682 · commit 09fd77f
-rw-r--r--Test.gd2
-rw-r--r--addons/swipe-detector/InputEventSwipe.gd5
-rw-r--r--addons/swipe-detector/SwipeDetector.gd8
-rw-r--r--addons/swipe-detector/package.json2
4 files changed, 11 insertions, 6 deletions
diff --git a/Test.gd b/Test.gd
index fd0a3a6..597e41b 100644
--- a/Test.gd
+++ b/Test.gd
@@ -8,3 +8,5 @@ func _ready():
func _input(event):
if event is InputEventSwipe:
print(event.direction)
+ print(event.start_position)
+ print(event.end_position)
diff --git a/addons/swipe-detector/InputEventSwipe.gd b/addons/swipe-detector/InputEventSwipe.gd
index 9e4f26c..1498e94 100644
--- a/addons/swipe-detector/InputEventSwipe.gd
+++ b/addons/swipe-detector/InputEventSwipe.gd
@@ -2,6 +2,5 @@ class_name InputEventSwipe
extends InputEventAction
var direction := Vector2.ZERO
-
-func _init(dir: Vector2) -> void:
- direction = dir.snapped(Vector2(.1, .1)) \ No newline at end of file
+var start_position := Vector2.ZERO
+var end_position := Vector2.ZERO
diff --git a/addons/swipe-detector/SwipeDetector.gd b/addons/swipe-detector/SwipeDetector.gd
index 916a658..d9d8716 100644
--- a/addons/swipe-detector/SwipeDetector.gd
+++ b/addons/swipe-detector/SwipeDetector.gd
@@ -13,7 +13,7 @@ func _ready():
timer.one_shot = true
-func _unhandled_input(event: InputEvent) -> void:
+func _input(event: InputEvent) -> void:
if not event is InputEventScreenTouch:
return
if event.pressed: # press
@@ -30,4 +30,8 @@ func set_swipe_start_position(position: Vector2) -> void:
func _end_detection(position: Vector2) -> void:
timer.stop()
var direction := (position - swipe_start_position).normalized()
- Input.parse_input_event(InputEventSwipe.new(direction))
+ var swipe = InputEventSwipe.new()
+ swipe.direction = direction
+ swipe.start_position = swipe_start_position
+ swipe.end_position = position
+ Input.parse_input_event(swipe)
diff --git a/addons/swipe-detector/package.json b/addons/swipe-detector/package.json
index 5570164..4a15dc7 100644
--- a/addons/swipe-detector/package.json
+++ b/addons/swipe-detector/package.json
@@ -1,6 +1,6 @@
{
"name": "@bendn/swipe-detector",
- "version": "1.0.0",
+ "version": "1.1.0",
"description": "godot swipe detector",
"main": "SwipeDetector.gd",
"scripts": {