-- standard multi-touch event listener
function circle:touch(e)
local target = circle -- get the object which received the touch event
circle.alpha = 0.5 -- make it less imposing
e.parent = rect -- store the parent object in the event
-- handle each phase of the touch event life cycle...
if (e.phase == "began") then
display.getCurrentStage():setFocus(target, e.id) -- set touch focus on this object
target.hasFocus = true -- remember that this object has the focus
return true -- indicate the event was handled
elseif (target.hasFocus) then -- this object is handling touches
if (e.phase == "moved") then -- move the display object with the touch
target.x, target.y = e.x, e.y
else -- "ended" and "cancelled" phases
display.getCurrentStage():setFocus(target, nil) -- remove touch focus
target.hasFocus = false -- this object no longer has the focus
end
rect:touch(e) -- send the event parameter to the rect object
return true -- indicate that we handled the touch and not to propagate it
end
return false -- if target is not responsible for this touch event return false
end