Difference between revisions of "B2.MouseJoint"
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
+ | <!-- GIDEROSOBJ:b2.MouseJoint --> | ||
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | '''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]]<br/> | ||
'''<translate>Available since</translate>:''' Gideros 2011.6<br/> | '''<translate>Available since</translate>:''' Gideros 2011.6<br/> | ||
Line 38: | Line 39: | ||
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Methods</translate> === | === <translate>Methods</translate> === | ||
− | [[Special:MyLanguage/b2.MouseJoint:getDampingRatio|b2.MouseJoint:getDampingRatio]] ''<translate>returns the damping ratio</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:getDampingRatio|b2.MouseJoint:getDampingRatio]] ''<translate>returns the damping ratio</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:getDampingRatio --> |
− | [[Special:MyLanguage/b2.MouseJoint:getFrequency|b2.MouseJoint:getFrequency]] ''<translate>returns the response frequency in Hertz</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:getFrequency|b2.MouseJoint:getFrequency]] ''<translate>returns the response frequency in Hertz</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:getFrequency --> |
− | [[Special:MyLanguage/b2.MouseJoint:getMaxForce|b2.MouseJoint:getMaxForce]] ''<translate>returns the maximum force in N</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:getMaxForce|b2.MouseJoint:getMaxForce]] ''<translate>returns the maximum force in N</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:getMaxForce --> |
− | [[Special:MyLanguage/b2.MouseJoint:getTarget|b2.MouseJoint:getTarget]] ''<translate>returns the x and y coordinates of the target point</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:getTarget|b2.MouseJoint:getTarget]] ''<translate>returns the x and y coordinates of the target point</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:getTarget --> |
− | [[Special:MyLanguage/b2.MouseJoint:setDampingRatio|b2.MouseJoint:setDampingRatio]] ''<translate>sets the damping ratio (0 = no damping, 1 = critical damping)</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:setDampingRatio|b2.MouseJoint:setDampingRatio]] ''<translate>sets the damping ratio (0 = no damping, 1 = critical damping)</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:setDampingRatio --> |
− | [[Special:MyLanguage/b2.MouseJoint:setFrequency|b2.MouseJoint:setFrequency]] ''<translate>sets the response frequency in Hertz</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:setFrequency|b2.MouseJoint:setFrequency]] ''<translate>sets the response frequency in Hertz</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:setFrequency --> |
− | [[Special:MyLanguage/b2.MouseJoint:setMaxForce|b2.MouseJoint:setMaxForce]] ''<translate>sets the maximum force in N</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:setMaxForce|b2.MouseJoint:setMaxForce]] ''<translate>sets the maximum force in N</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:setMaxForce --> |
− | [[Special:MyLanguage/b2.MouseJoint:setTarget|b2.MouseJoint:setTarget]] ''<translate>updates the target point</translate>''<br/> | + | [[Special:MyLanguage/b2.MouseJoint:setTarget|b2.MouseJoint:setTarget]] ''<translate>updates the target point</translate>''<br/><!-- GIDEROSMTD:b2.MouseJoint:setTarget --> |
| style="width: 50%; vertical-align:top;"| | | style="width: 50%; vertical-align:top;"| | ||
=== <translate>Events</translate> === | === <translate>Events</translate> === | ||
=== <translate>Constants</translate> === | === <translate>Constants</translate> === | ||
|} | |} |
Revision as of 14:55, 31 August 2018
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 a soft constraint with a maximum force. This allows the constraint to stretch and 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 |