Why are the event.x and event.y values always 0?
local function testDragDynamicBody() local function touch(e) if (e.phase == "began") then e.target.hasFocus = true display.currentStage:setFocus(e.target) e.target.prev = e return true elseif (e.target.hasFocus) then e.target.x, e.target.y = e.target.x+(e.x-e.target.prev.x), e.target.y+(e.y-e.target.prev.y) e.target.prev = e if (e.phase == "moved") then else e.target.hasFocus = nil display.currentStage:setFocus(nil) end return true end return false end local function collision(e) dump(e) return false end local function addBody(n,x,y,w,h) local a = display.newRect( x, y, w or 100, h or 10 ) a.name = n physics.addBody( a, "dynamic", { isSensor=true } ) a:addEventListener( "touch", touch ) a:addEventListener( "collision", collision ) return a end local a, b = addBody( "a", 100, 100 ), addBody( "b", 400, 100 ) Runtime:addEventListener( "collision", collision ) end testDragDynamicBody()
(Please excuse the terrible touch handling.)