Corona SDK Pro Tip of the Day #16
Touch blocking

Use a helper function to quickly block touches for an object.

Often you need to stop touch or tap events, for example for a popup window. Ideally you need to block both of them and also account for invisible objects.

Here is my helper function.

local _M = {}

local function rt() return true end  
function _M.returnTrue(obj)  
    if obj then
        obj:addEventListener('touch', rt)
        obj:addEventListener('tap', rt)
        obj.isHitTestable = true
    else
        return rt
    end
end

return _M  

If I want to block touches for say a background, I'd write:

app.returnTrue(myBackground)  

Or if I just need to return true for some other event, make it like a stub:

myObject:addEventListener('customEvent', app.returnTrue())  

Notice parenthesis here. I call this function and without arguments it returns another function, which in turn does return true no matter what.

Indie Game Developer