B2.MouseJoint
Supported platforms:
Available since: Gideros 2011.6
Inherits from: b2.Joint
Description
A mouse joint is used to make a point on a body track a specified world point. This is a soft constraint with a maximum force. This allows the constraint to stretch without applying huge forces.
Examples
Mouse joint
--create empty box2d body for joint
local ground = world:createBody({})
--joint with dummy body
local mouseJoint = nil
-- create a mouse joint on mouse down
function self:onMouseDown(event)
local jointDef = b2.createMouseJointDef(ground, body, event.x, event.y, 100000)
mouseJoint = world:createJoint(jointDef)
end
-- update the target of mouse joint on mouse move
function self:onMouseMove(event)
if mouseJoint ~= nil then
mouseJoint:setTarget(event.x, event.y)
end
end
-- destroy the mouse joint on mouse up
function self:onMouseUp(event)
if mouseJoint ~= nil then
world:destroyJoint(mouseJoint)
mouseJoint = nil
end
end
Methodsb2.MouseJoint:getDampingRatio returns the damping ratio |
EventsConstants |