Created
November 15, 2012 05:35
-
-
Save erinlin/4076826 to your computer and use it in GitHub Desktop.
Corona: slide event example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------- | |
-- 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