Function
love.physics.newMouseJoint( body, x, y )
Create a joint between a body and the mouse.

This joint actually connects the body to a fixed point in the world. To make it follow the mouse, the fixed point must be updated every timestep (example below).

The advantage of using a MouseJoint instead of just changing a body position directly is that collisions and reactions to other joints are handled by the physics engine.

Synopsis
joint = love.physics.newMouseJoint( body, x, y )
Parameters
body body The body to attach to the mouse.
x number The x position of the connecting point.
y number The y position of the connecting point.
Returns
joint Joint The new mouse joint.
See Also
Joint   MouseJoint   MouseJoint:setTarget  
Examples
  1. function love.load()
  2.   w=love.physics.newWorld(1000,1000)
  3.   b=love.physics.newBody(w,love.mouse.getPosition())
  4.   s=love.physics.newCircleShape(b,0,0,20)
  5.   b:setMassFromShapes()
  6.   j=love.physics.newMouseJoint(b,love.mouse.getPosition())
  7. end
  8.  
  9. function love.draw()
  10.   love.graphics.circle("fill",b:getX(),b:getY(),s:getRadius(),20)
  11. end
  12.  
  13. function love.update(dt)
  14.   j:setTarget(love.mouse.getPosition())
  15.   w:update(dt)
  16. end
Copyright © 2006-2010 LÖVE Development Team.