arypbatista/godot-swipe-detector

Delimit swipe area with Area2D node. Allow multiple Area2D instances to achieve independant simultaneous swipes.

Closed this issue · 7 comments

Two options came to my mind when thinking a solution to this requested feature:

  1. To attach the swipe detector script to an Area2D, in a way you can set two (or more) different swipe detectors. Swipe detects will occur independently in each area. For example, if you are programming a mobile pong and you want both players to swipe at th same time, you could add one Area2D swipe detector node for the left side of the screen and an other for the right side of the screen.

  2. Add Area2D children into the SwipeDetector node, so you will get more information on the gesture object regarding the Area2D were it is being executed. Signals could be triggered once per Area2D child.

We could also include both 1 and 2.

Any thoughts?

This enhancement was originated from a request from Arnav Singh (I don't have your Github User yet)

Hi Ary,

This is Arnav again. I was wondering whether it was possible to have have two swipes occurring at the same time? I am making a pong like game and want to control the paddles by swiping. How would i go about getting this to work? Would i perhaps just make two swipe detection scenes and instance them to the scene I want or??

Please help!

Thanks,
Arnav

B2ST commented

Sounds good man!

B2ST commented

Let me know if i can help in anyway :)

Yeah, can you help me test the implementation?

I have pushed a branch called detection-areas. I have included an example called "SwipeAreasExample" and tested it in my phone. But it would be great if you can test it out in your pong-like game.

B2ST commented

yer no problem. I will do it now

B2ST commented

I have tried and am getting some errors. I had a look at how you set it up, and you have instanced your swipe detector scene into the detection area scene and put two child area2d nodes. I have done that too. Do we need to have the collision areas? if so, i have tried this as well. When I swipe, it gives me an error in the swipe_started function which passes in points. I have a feeling I havent set it up correctly. Could you please give the steps? Thanks

Edit: the error I got was because i was using the old functions which passed in points. what exactly is a partial gesture? and also... do we need to have the collision areas? will it interfere or affect physics bodies like the ball in my pong game?? Thanks

Yeah, sorry. Forgot to tell you the API was changed. A partial gesture is the gesture being captured. So you can access what you before called point through partial_gesture.last_point().

We need collision areas since I use input events from Area2D. They should not interfere with the game. Maybe it depends on how you set up the specific Area2Ds, but it doesn't override space by default.

Implemented on pull request #14