alestane icon

Region tracker

alestane | PRO | 05/01/13 12:35:43 AM UTC | 0 ⭐ | 351 👁️ | Never ⏰ | []
Lua |

480 B

|

None

|

0 👍

/

0 👎

local touches = {}
 
local function monitor(event)
    if event.phase == 'began' or event.phase == 'moved' then
        touches[event.id] = event.target
    else
        touches[event.id] = nil
    end
end
 
function touchesInRegion(r)
    local n = 0
    for touch, target in pairs(touches) do
        if target == r then
            n = n + 1
        end
    end
    return n
end
 
function trackRegion(r)
    r:addEventListener('touch', monitor)
end
 
function ignoreRegion(r)
    r:removeEventListener('touch', monitor)
end

Comments