Skip to content

Instantly share code, notes, and snippets.

@figengungor
Created June 13, 2013 22:16
Show Gist options
  • Select an option

  • Save figengungor/5777852 to your computer and use it in GitHub Desktop.

Select an option

Save figengungor/5777852 to your computer and use it in GitHub Desktop.
Dragging a display object in Corona
-- create object
local myObject = display.newRect( 0, 0, 100, 100 )
myObject:setFillColor( 255 )
-- touch listener function
function myObject:touch( event )
if event.phase == "began" then
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
elseif event.phase == "moved" then
local x = (event.x - event.xStart) + self.markX --event.xStart gives the point where your finger touch on the object at first
local y = (event.y - event.yStart) + self.markY --event.y gives where your finger is now
self.x, self.y = x, y -- move object based on calculations above
end
return true
end
-- make 'myObject' listen for touch events
myObject:addEventListener( "touch", myObject )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment