Search code examples
luahovertouchcoronasdk

Corona SDK - event "touch", phase "moved" - detect if currently over an object


For example I have a couple of static circles (or some other objects) drawn, and called

circle:addEventListener("touch", onTouch)

for all of them.

Inside function onTouch is there a simple way to find out if the new touching coordinates are over another object?

local function onTouch(event)
    local c = event.target
    local phase = event.phase
    if (phase == "moved") then
        -- HERE
        -- I would like to receive a pointer to the object I'm hovering over
    end
    return true  -- Prevents touch propagation to underlying objects
end

Solution

  • Save references to display objects in table circles. Next, inside onTouch function in moved phase iterate over items in table circles to find objects you hovering over. You can use property object.contentBounds to find boundaries of an object, in content coordinates.