Hello,
There are some problems with this code:
local function handleTouch( event ) if event.phase == "began" then audio.play(flush) transition.to(rect, {rotation = -20, time = 100}) elseif event.phase == "ended" then transition.to(rect, {rotation = 0, time = 100}) end end rect:addEventListener( "touch", handleTouch )
Sometimes when I touch the the ‘rect’ and let go, it goes to rotation -20 instead of back to 0. How can I fix this?
here is the full code
display.setStatusBar( display.HiddenStatusBar ) local rect = display.newRect( 123,0, 50, 12 ) rect:setFillColor( 0.64, 0.64, 0.64 ) rect.x = display.contentCenterX rect.y = display.contentCenterY local function handleTouch( event ) if event.phase == "began" then audio.play(flush) transition.to(rect, {rotation = -20, time = 100}) elseif event.phase == "ended" then transition.to(rect, {rotation = 0, time = 100}) end end rect:addEventListener( "touch", handleTouch )