Detect which direction drag is coming from

I’m developing a game wherein there is a grid with coloured dots, and the player has to connect the dots together (by dragging and drawing a line from point to point), but fill up the grid without the lines intersecting.

My question is, is there a way to know which direction the drag is coming from?

[import]uid: 186198 topic_id: 31990 reply_id: 331990[/import]

Quite easy to do, this little (and very basic) code snippet may help you.

Basically it checks the X value of where the touch started and against where the touch is, and prints what direction the swipe is.

[lua]menuSwipe = {}
Runtime:addEventListener(“touch”, menuSwipe)
function menuSwipe:touch( event )
if event.xStart < event.x then
print ‘swipe right’
elseif event.xStart > event.x then
print ‘swipe left’
end
end[/lua] [import]uid: 62706 topic_id: 31990 reply_id: 127568[/import]

Awesome! Thanks :smiley:

So I guess the same concept is applied when checking where the swiping is going. Thanks a lot. :slight_smile:

[import]uid: 186198 topic_id: 31990 reply_id: 127591[/import]

Quite easy to do, this little (and very basic) code snippet may help you.

Basically it checks the X value of where the touch started and against where the touch is, and prints what direction the swipe is.

[lua]menuSwipe = {}
Runtime:addEventListener(“touch”, menuSwipe)
function menuSwipe:touch( event )
if event.xStart < event.x then
print ‘swipe right’
elseif event.xStart > event.x then
print ‘swipe left’
end
end[/lua] [import]uid: 62706 topic_id: 31990 reply_id: 127568[/import]

Awesome! Thanks :smiley:

So I guess the same concept is applied when checking where the swiping is going. Thanks a lot. :slight_smile:

[import]uid: 186198 topic_id: 31990 reply_id: 127591[/import]