0
votes

I'm new in Corona SDK and I would like some help: I want to check the direction of the user swipe, I have an object:

local Rect = display.newRect(30,30,30,30)
Rect:setFillColor(255,0,0)

and I want to add to him a Listener

Runtime:addEventListener("touch",SwipeTouchEvent)

in the function I want to check if there was a swipe, and for what direction the swipe was. if is was up add 1 to int up; if it was down, add 1 to int down; if it was right add 1 to int right and if it was left, add 1 to int left; and display all the ints on the screen... thanks for helpers!

1

1 Answers

1
votes

Here is an article that talks about how to change scenes by swiping left or right. see if you can pull this apart and take what you need.

https://forums.coronalabs.com/topic/33708-swipe-left-or-right-to-change-scenes/

hint :

local function startDrag(event)
        local swipeLength = math.abs(event.x - event.xStart) 
        print(event.phase, swipeLength)
        local t = event.target
        local phase = event.phase
        if "began" == phase then
            return true
        elseif "moved" == phase then
        elseif "ended" == phase or "cancelled" == phase then
            if event.xStart > event.x and swipeLength > 50 then 
                print("Swiped Left")
            elseif event.xStart < event.x and swipeLength > 50 then 
                print( "Swiped Right" )
            end 
        end
    end