Swipe direction detection
Closed this issue · 3 comments
Hi, I need for my game a direction detection. So I implemented it dirty for me. I want to contribute it to this project and have a Question:
is it okay to give the gesture object a new method, called String get_direction() or is it better to emit an event whenever a direction is detected?
Hello @ppfeiler ! I am glad to receive some contribution from you!
I think yeah, we should create a get_direction method. But why an String? I mean, what is a direction for you?
If we are returning directions, I would add constants to the class or detector, so we can pass strings or integers, and users will use our constants interface. So, we can think of this signature: Direction get_direction()
.
Once again, what is a direction for you? Just right or left? The four orthogonal directions? The eight orthogonal plus diagonal directions? Maybe we could just return a Vector2
with the direction. I think that would be more versatile. We could have a simplified API if you want, in a way the user does not have to interpret the vector, let's say:
Possible new methods:
Direction get_direction()
Vector2 get_direction_vector()
For the event, we could have signals like "swiped_left", "swiped_right" or something like that, but we need first understand what we specifically want to implement here.
Alsoooooooo, another matter here is how do you calculate direction. How would you do it? A line swipe is easy. A curve swipe might be easy to decide it's direction too. But think on complex gestures.
Interesting feature!
I think yeah, we should create a get_direction method. But why an String? I mean, what is a direction for you?
I used the String because I used it so in my game. The PR was like an example, I should have added the WIP tag to it :)
Once again, what is a direction for you? Just right or left? The four orthogonal directions? The eight orthogonal plus diagonal directions?
I think for the first version of this feature we could just use the four orthogonal directions.
For the event, we could have signals like "swiped_left", "swiped_right" or something like that, but we need first understand what we specifically want to implement here.
For the event I would only implement the four orthogonal directions: swiped_[top|down|left|right]
. When you need the eight directions, you can call Direction get_direction()
or Vector2 get_direction_vector()
Alsoooooooo, another matter here is how do you calculate direction. How would you do it? A line swipe is easy. A curve swipe might be easy to decide it's direction too. But think on complex gestures.
I think my calculation is for the four direction correct. For the eight direction I have to think for a better calcilation.
What do you think about splitting this feature into 2 parts:
- Version1: only the four directions
- Version2: all eight directions
Hi, just added this feature, with 8-directions.
I changed the calculation to use the direction angle. Yours worked fine, this is just better to calculate the direction index.
I will add issues for future improvements to this feature.