Difference between revisions of "B2.Fixture"

From GiderosMobile
m (Text replacement - "</source" to "</syntaxhighlight")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<!-- GIDEROSOBJ:b2.Fixture -->
 
<!-- GIDEROSOBJ:b2.Fixture -->
'''<translate>Supported platforms</translate>:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
+
'''Supported platforms:''' [[File:Platform android.png]][[File:Platform ios.png]][[File:Platform mac.png]][[File:Platform pc.png]][[File:Platform html5.png]][[File:Platform winrt.png]][[File:Platform win32.png]]<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Available since:''' Gideros 2011.6<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
A fixture is used to attach a shape to a body for collision detection. A fixture inherits its<br />
+
A fixture is used to attach a shape to a body for collision detection. A fixture inherits its transform from its parent. Fixtures hold additional non-geometric data such as friction, collision filters, etc.
transform from its parent. Fixtures hold additional non-geometric data such as friction, collision filters, etc.<br />
+
 
Fixtures are created via [[Special:MyLanguage/b2.Body:createFixture|b2.Body:createFixture]].<br />
+
Fixtures are created via [[b2.Body:createFixture]].
<br /></translate>
+
 
=== <translate>Examples</translate> ===
+
=== Examples ===
'''Example of fixtures collision filtering'''<br/>
+
'''Example of fixtures collision filtering'''
<source lang="lua">local BALL_MASK = 1
+
<syntaxhighlight lang="lua">
 +
local BALL_MASK = 1
 
local CRATE_MASK = 2
 
local CRATE_MASK = 2
 
local WALL_MASK = 4
 
local WALL_MASK = 4
Line 42: Line 43:
 
friction = 1, restitution = 0.3}
 
friction = 1, restitution = 0.3}
 
-- walls will collide with both balls and crates
 
-- walls will collide with both balls and crates
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})</source>
+
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})
 +
</syntaxhighlight>
 +
 
 
{|-
 
{|-
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Methods</translate> ===
+
=== Methods ===
[[Special:MyLanguage/b2.Fixture:getBody|b2.Fixture:getBody]] ''<translate>returns the parent body of this fixture</translate>''<br/><!-- GIDEROSMTD:b2.Fixture:getBody -->
+
[[b2.Fixture:getBody]] ''returns the parent body of this fixture''<br/><!--GIDEROSMTD:b2.Fixture:getBody() returns the parent body of this fixture-->
[[Special:MyLanguage/b2.Fixture:getFilterData|b2.Fixture:getFilterData]] ''<translate>returns the contact filtering data</translate>''<br/><!-- GIDEROSMTD:b2.Fixture:getFilterData -->
+
[[b2.Fixture:getFilterData]] ''returns the contact filtering data''<br/><!--GIDEROSMTD:b2.Fixture:getFilterData() returns the contact filtering data-->
[[Special:MyLanguage/b2.Fixture:isSensor|b2.Fixture:isSensor]] ''<translate>is this fixture a sensor (non-solid)?</translate>''<br/><!-- GIDEROSMTD:b2.Fixture:isSensor -->
+
[[b2.Fixture:isSensor]] ''is this fixture a sensor (non-solid)?''<br/><!--GIDEROSMTD:b2.Fixture:isSensor() is this fixture a sensor (non-solid)?-->
[[Special:MyLanguage/b2.Fixture:setFilterData|b2.Fixture:setFilterData]] ''<translate>sets the contact filtering data</translate>''<br/><!-- GIDEROSMTD:b2.Fixture:setFilterData -->
+
[[b2.Fixture:setFilterData]] ''sets the contact filtering data''<br/><!--GIDEROSMTD:b2.Fixture:setFilterData(filterData) sets the contact filtering data-->
[[Special:MyLanguage/b2.Fixture:setSensor|b2.Fixture:setSensor]] ''<translate>sets if this fixture is a sensor</translate>''<br/><!-- GIDEROSMTD:b2.Fixture:setSensor -->
+
[[b2.Fixture:setSensor]] ''sets if this fixture is a sensor''<br/><!--GIDEROSMTD:b2.Fixture:setSensor(sensor) sets if this fixture is a sensor-->
 +
 
 
| style="width: 50%; vertical-align:top;"|
 
| style="width: 50%; vertical-align:top;"|
=== <translate>Events</translate> ===
+
=== Events ===
=== <translate>Constants</translate> ===
+
=== Constants ===
 
|}
 
|}
 +
 +
----
 +
*'''[[LiquidFun]]'''

Latest revision as of 16:57, 12 July 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2011.6

Description

A fixture is used to attach a shape to a body for collision detection. A fixture inherits its transform from its parent. Fixtures hold additional non-geometric data such as friction, collision filters, etc.

Fixtures are created via b2.Body:createFixture.

Examples

Example of fixtures collision filtering

local BALL_MASK = 1
local CRATE_MASK = 2
local WALL_MASK = 4
 
-- ball
local body = world:createBody{type = b2.DYNAMIC_BODY}
local circle = b2.CircleShape.new(0, 0, radius)
local fixture = body:createFixture{shape = circle, density = 1.0, 
friction = 0.1, restitution = 0.2}
-- ball will collide with other ball and wall
fixture:setFilterData({categoryBits = BALL_MASK, maskBits = BALL_MASK + WALL_MASK, groupIndex = 0})

local body = world:createBody{type = b2.DYNAMIC_BODY}
local poly = b2.PolygonShape.new()
poly:setAsBox(width, height)
local fixture = body:createFixture{shape = poly, density = 1.0, 
friction = 0.1, restitution = 0.2}
-- crate will collide with other crate and wall
fixture:setFilterData({categoryBits = CRATE_MASK, maskBits = CRATE_MASK + WALL_MASK, groupIndex = 0})

local body = world:createBody{type = b2.STATIC_BODY}
local chain = b2.ChainShape.new()
chain:createLoop(
	0,0,
	application:getContentWidth(), 0,
	application:getContentWidth(), application:getContentHeight(),
	0, application:getContentHeight()
)
local fixture = body:createFixture{shape = chain, density = 1.0, 
friction = 1, restitution = 0.3}
-- walls will collide with both balls and crates
fixture:setFilterData({categoryBits = WALL_MASK, maskBits = CRATE_MASK + BALL_MASK, groupIndex = 0})

Methods

b2.Fixture:getBody returns the parent body of this fixture
b2.Fixture:getFilterData returns the contact filtering data
b2.Fixture:isSensor is this fixture a sensor (non-solid)?
b2.Fixture:setFilterData sets the contact filtering data
b2.Fixture:setSensor sets if this fixture is a sensor

Events

Constants