While ago, Brent Sorrentino post a tutorial on the blog called Parallax Simplified
I was wondering if somebody could help me add some swipe and spring effects to the touch event. I’m looking at the same effect as when you scroll with a Tableview in iOS, with some residual movement that slows down gradually when you remove your finger after a swipe and the spring effect when you reach the edge.
Any ideas please?? This is the missing piece before the end of my project!
This is the touch event code:
local function touchScreen( event ) local stageID = event.target local refGroup = stageID.refGroup ; local paraGroups = stageID.paraGroups local eventX = event.x ; local eventY = event.y if ( #paraGroups \< 1 ) then return end if ( event.phase == "began" ) then for i=1,#paraGroups do paraGroups[i].offsetX = eventX - refGroup.x paraGroups[i].offsetY = eventY - refGroup.y end elseif ( event.phase == "moved" ) then local xDif = eventX - refGroup.offsetX local yDif = eventY - refGroup.offsetY --If you are NOT limiting the boundaries of your world, comment out these 2 lines. if ( xDif \< stageID.xMin ) then xDif = stageID.xMin elseif ( xDif \> stageID.xMax ) then xDif = stageID.xMax end if ( yDif \< stageID.yMin ) then yDif = stageID.yMin elseif ( yDif \> stageID.yMax ) then yDif = stageID.yMax end for i=1,#paraGroups do local group = paraGroups[i] group.x = xDif \* group.distanceRatio group.y = yDif \* group.distanceRatio group = nil end xDif, yDif = nil,nil end stageID, refGroup, paraGroups, eventX, eventY = nil,nil,nil,nil,nil return true end stage:addEventListener( "touch", touchScreen )