swipe control

hi,i was wondering if it is possible to use swipe control in corona sdk??

i created a game called insano cabby and now i want to experiment with it,initially i used

tap event listener and created two buttons to move the player right and left.

i thing it would be even more fun if i remove the tap buttons 

and add swipe gesture to it.

so is it possible to add swipe in corona sdk???

Sure. Does this one work for you? https://coronalabs.com/blog/2014/09/16/tutorial-swiping-an-object-to-fixed-points/

hi,thanks for the reply that is great,does it work on simulator also?? 

You can always try :slight_smile:

You could calculate the beginning coordinates of the touch end the end coordinate. Also save the begin coordinates of the touch.
Now you can check if the begin coordinates are smaller or greater than the end coordinates. If it’s smaller you could make your character go to left, if it’s larger you could go to the right.
I hope this helps :slight_smile:

Let me add a little to this.

When you get your “moved” phase, there is an event.xStart and event.yStart value in addition to event.x and event.y.

If you only care about horizontal swipes then you simply need to decide how much movement is a swipe and do something like:

local isSwipe = math.abs(event.x - event.xStart) \> 10 if isSwipe then     -- do something end

if you care about vertical swipes, then use the .y and.yStart values.  If direction is important, then you need a bit more math.

local xDistance = math.abs(event.x - event.xStart) local yDistance = math.abs(event.y - event.yStart) local distanceMoved = math.sqrt( xDistance \* xDistance + yDistance \* yDistance)

And with that info you can also get the angle of the swipe with a little trigonometry.

Rob

Sure. Does this one work for you? https://coronalabs.com/blog/2014/09/16/tutorial-swiping-an-object-to-fixed-points/

hi,thanks for the reply that is great,does it work on simulator also?? 

You can always try :slight_smile:

You could calculate the beginning coordinates of the touch end the end coordinate. Also save the begin coordinates of the touch.
Now you can check if the begin coordinates are smaller or greater than the end coordinates. If it’s smaller you could make your character go to left, if it’s larger you could go to the right.
I hope this helps :slight_smile:

Let me add a little to this.

When you get your “moved” phase, there is an event.xStart and event.yStart value in addition to event.x and event.y.

If you only care about horizontal swipes then you simply need to decide how much movement is a swipe and do something like:

local isSwipe = math.abs(event.x - event.xStart) \> 10 if isSwipe then     -- do something end

if you care about vertical swipes, then use the .y and.yStart values.  If direction is important, then you need a bit more math.

local xDistance = math.abs(event.x - event.xStart) local yDistance = math.abs(event.y - event.yStart) local distanceMoved = math.sqrt( xDistance \* xDistance + yDistance \* yDistance)

And with that info you can also get the angle of the swipe with a little trigonometry.

Rob