Created
April 16, 2018 02:09
-
-
Save Mr-Coxall/63d5cc75dabc9351882ee764b24ad125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Comprehensive touch code | |
local theBall = display.newImage( "./assets/sprites/ball.png" ) | |
theBall.x = display.contentCenterX | |
theBall.y = display.contentCenterY | |
theBall.id = "ball object" | |
function theBall:touch( event ) | |
if ( event.phase == "began" ) then | |
print( "Touch event began on: " .. self.id ) | |
-- Set touch focus | |
display.getCurrentStage():setFocus( self ) | |
self.isFocus = true | |
elseif ( self.isFocus ) then | |
if ( event.phase == "moved" ) then | |
print( "Moved phase of touch event detected." ) | |
elseif ( event.phase == "ended" or event.phase == "cancelled" ) then | |
-- Reset touch focus | |
display.getCurrentStage():setFocus( nil ) | |
self.isFocus = nil | |
print( "Touch event ended on: " .. self.id ) | |
end | |
end | |
return true | |
end | |
theBall:addEventListener( "touch", theBall ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment