Skip to content

Instantly share code, notes, and snippets.

@erinlin
Created November 15, 2012 05:35
Show Gist options
  • Save erinlin/4076826 to your computer and use it in GitHub Desktop.
Save erinlin/4076826 to your computer and use it in GitHub Desktop.
Corona: slide event example
-------------------------------------
-- group slide event
-- Erin Lin
-------------------------------------
local isActive = true
local slide = function(event)
if not isActive then return end
local W = display.contentWidth * .5
local dis = 40
local pos = (event.xStart < W and "L") or "R"
local len = event.xStart - event.x
if "began" == event.phase then
display.getCurrentStage():setFocus( group )
elseif "moved" == event.phase then
if pos == "L" and len < -dis then
print("slide", "toLeft")
isActive = false
-- code here
elseif pos == "R" and len > dis then
print("slide", "toRight")
isActive = false
-- code here
end
elseif "ended" == event.phase then
print("click")
display.getCurrentStage():setFocus( nil )
if math.abs(len) < dis then
-- code here
end
end
end
group:addEventListener("touch", slide)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment