Difference between revisions of "B2.MouseJoint"

From GiderosMobile
Line 2: Line 2:
 
'''Supported platforms:''' android, ios, mac, pc<br/>
 
'''Supported platforms:''' android, ios, mac, pc<br/>
 
'''Available since:''' Gideros 2011.6<br/>
 
'''Available since:''' Gideros 2011.6<br/>
=== Description ===
+
=== <translate>Description</translate> ===
 
<translate><br />
 
<translate><br />
 
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.<br />
 
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.<br />
 
<br /></translate>
 
<br /></translate>
=== Examples ===
+
=== <translate>Examples</translate> ===
 
'''Mouse joint'''<br/>
 
'''Mouse joint'''<br/>
 
<source lang="lua">--create empty box2d body for joint
 
<source lang="lua">--create empty box2d body for joint
Line 36: Line 36:
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== Methods ===
+
=== <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/>
 
[[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/>
Line 46: Line 46:
 
[[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/>
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== Events ===
+
=== <translate>Events</translate> ===
=== Constants ===
+
=== <translate>Constants</translate> ===
 
|}
 
|}

Revision as of 07:28, 24 August 2018

Supported platforms: android, ios, mac, pc
Available since: Gideros 2011.6

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

Methods

b2.MouseJoint:getDampingRatio returns the damping ratio
b2.MouseJoint:getFrequency returns the response frequency in Hertz
b2.MouseJoint:getMaxForce returns the maximum force in N
b2.MouseJoint:getTarget returns the x and y coordinates of the target point
b2.MouseJoint:setDampingRatio sets the damping ratio (0 = no damping, 1 = critical damping)
b2.MouseJoint:setFrequency sets the response frequency in Hertz
b2.MouseJoint:setMaxForce sets the maximum force in N
b2.MouseJoint:setTarget updates the target point

Events

Constants