Sunday, 28 July 2013

Touch listener in Corona SDK

We can assign touch listener to an object in corona as follows:


-- Create the object --
local rect = display.newRect(100,100,50,50)
rect:setFillColor(255,0,0)

-- Create the touch function --
local function myTouchFunction(event)
    if(e.phase=="began")then
         print("Touch begins...")
    elseif(e.phase=="moved")then
         print("Touch moved...")
    elseif(e.phase=="ended")then
         print("Touch ended...")
    end
end

-- Create the listener to the object --
rect:addEventListener("touch",myTouchFunction)








No comments:

Post a Comment