[FIXED] Dragging Objects

I am trying to allow a user to touch and drag a paddle in a game. I am using a modified version of the code in the function dragBody() from gameUI.lua in the Air Hockey sample app. (Multitouch is not enabled in my game, nor do I want it to be.) When I try to drag the paddle in the simulator, nothing happens. There are no error messages in the terminal either. Here is my code:

function dragBody(event)  
 local body = event.target  
 local stage = display.getCurrentStage()  
 if event.phase=="began" then  
 stage:setFocus(body)  
 body.isFocus = true  
 body.tempJoint = physics.newJoint( "touch", body, event.x, event.y )  
 end  
 if event.phase=="moved" then  
 body.tempJoint:setTarget( event.x, event.y )  
 elseif event.phase=="ended" or event.phase=="canceled" then  
 stage:setFocus(nil)  
 body.isFocus = false   
 body.tempJoint:removeSelf()  
 end  
 return true  
end  
  
paddle:addEventListener("touch", dragBody)  

[import]uid: 23768 topic_id: 12320 reply_id: 312320[/import]

Try using the drag function from the “Drag Platforms” sample app. Works great for me. [import]uid: 31262 topic_id: 12320 reply_id: 44852[/import]

@aaaron Thanks :slight_smile: it works fine now [import]uid: 23768 topic_id: 12320 reply_id: 44853[/import]