Difference between revisions of "love.physics.newMouseJoint"

m (Changed the type 'body' to the proper 'Body'.)
Line 2: Line 2:
  
 
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).
 
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.  
 
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.  
Line 40: Line 39:
 
== See Also ==
 
== See Also ==
 
* [[parent::love.physics]]
 
* [[parent::love.physics]]
 +
* [[Constructs::MouseJoint]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Create a joint between a body and the mouse.
+
{{#set:Description=Create a joint between a body and the mouse.}}
}}
+
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.physics.newMouseJoint}}
 
{{i18n|love.physics.newMouseJoint}}

Revision as of 11:05, 25 March 2011

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.

Function

Synopsis

joint = love.physics.newMouseJoint( body, x, y )

Arguments

Body body
The body to attach to the mouse.
number x
The x position of the connecting point.
number y
The y position of the connecting point.

Returns

Joint joint
The new mouse joint.

Examples

function love.load()
  w=love.physics.newWorld(1000,1000)
  b=love.physics.newBody(w,love.mouse.getPosition())
  s=love.physics.newCircleShape(b,0,0,20)
  b:setMassFromShapes()
  j=love.physics.newMouseJoint(b,love.mouse.getPosition())
end

function love.draw()
  love.graphics.circle("fill",b:getX(),b:getY(),s:getRadius(),20)
end

function love.update(dt)
  j:setTarget(love.mouse.getPosition())
  w:update(dt)
end

See Also


Other Languages