Advertisement
alestane

Region tracker

Apr 30th, 2013
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.48 KB | None | 0 0
  1. local touches = {}
  2.  
  3. local function monitor(event)
  4.     if event.phase == 'began' or event.phase == 'moved' then
  5.         touches[event.id] = event.target
  6.     else
  7.         touches[event.id] = nil
  8.     end
  9. end
  10.  
  11. function touchesInRegion(r)
  12.     local n = 0
  13.     for touch, target in pairs(touches) do
  14.         if target == r then
  15.             n = n + 1
  16.         end
  17.     end
  18.     return n
  19. end
  20.  
  21. function trackRegion(r)
  22.     r:addEventListener('touch', monitor)
  23. end
  24.  
  25. function ignoreRegion(r)
  26.     r:removeEventListener('touch', monitor)
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement