joelwe

Untitled

Apr 13th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.63 KB | None | 0 0
  1. local myObj = display.newRect(display.contentWidth * 0.5, display.contentHeight * 0.5, 25, 25)
  2. myObj.strokeWidth = 3
  3. myObj:setFillColor(140, 140, 140)
  4. myObj:setStrokeColor(180, 180, 180)
  5.  
  6. local onTouch = function( event )
  7.     if event.phase == "began" or event.phase == "moved" then
  8.     local objDistance = math.sqrt((event.x-myObj.x)^2+(event.y-myObj.y)^2)
  9.     local objVelocity = 0.1
  10.         local objTime = objDistance / objVelocity
  11.         local tween = transition.to( myObj, { x = event.x, y = event.y, time = objTime } )
  12.     end
  13. end
  14. local function startGame()
  15.     Runtime:addEventListener( "touch", onTouch )  
  16. end
  17. startGame()
Advertisement
Add Comment
Please, Sign In to add comment