Class b2Fixture

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 b2Body::CreateFixture.

warning

you cannot reuse fixtures.

Index

Methods

Methods

public GetAABB(): b2AABB

Get the fixture's AABB. This AABB may be enlarge and/or stale. If you need a more accurate AABB, compute it using the shape and the body transform.

Returns

b2AABB

Fiture's AABB.

public GetBody(): b2Body

Get the parent body of this fixture. This is NULL if the fixture is not attached.

Returns

b2Body

The parent body.

public GetDensity(): number

Get the density of this fixture.

Returns

number

Density

public GetFilterData(): b2FilterData

Get the contact filtering data.

Returns

b2FilterData

Filter data.

public GetFriction(): number

Get the coefficient of friction.

Returns

number

Friction.

public GetMassData(massData?: b2MassData): b2MassData

Get the mass data for this fixture. The mass data is based on the density and the shape. The rotational inertia is about the shape's origin. This operation may be expensive.

Parameters

  • massData?: b2MassData optional

    This is a reference to a valid b2MassData, if it is null a new b2MassData is allocated and then returned. Default = null.

Returns

b2MassData

Mass data.

public GetNext(): b2Fixture

Get the next fixture in the parent body's fixture list.

Returns

b2Fixture

Next fixture.

public GetRestitution(): number

Get the coefficient of restitution.

Returns

number

Restitution.

public GetShape(): b2Shape

Get the child shape. You can modify the child shape, however you should not change the number of vertices because this will crash some collision caching mechanisms.

Returns

b2Shape

Fixture shape.

public GetType(): number

Get the type of the child shape. You can use this to down cast to the concrete shape.

Returns

number

Shape type enum.

public GetUserData(): any

Get the user data that was assigned in the fixture definition. Use this to store your application specific data.

Returns

any

User provided data. Cast to your object type.

public IsSensor(): boolean

Is this fixture a sensor (non-solid)?

Returns

boolean

True if the shape is a sensor, otherwise false.

public RayCast(output: b2RayCastOutput, input: b2RayCastInput): boolean

Perform a ray cast against this shape.

Parameters

Returns

boolean

True if the ray hits the shape, otherwise false.

public SetDensity(density: number)

Set the density of this fixture. This will not automatically adjust the mass of the body. You must call b2Body::ResetMassData to update the body's mass.

Parameters

  • density: number

    The new density.

public SetFilterData(filter: any)

Set the contact filtering data. This will not update contacts until the next time step when either parent body is active and awake.

Parameters

  • filter: any

    The new filter data.

public SetFriction(friction: number)

Set the coefficient of friction.

Parameters

  • friction: number

    The new friction coefficient.

public SetRestitution(restitution: number)

Get the coefficient of restitution.

Parameters

  • restitution: number

public SetSensor(sensor: boolean)

Set if this fixture is a sensor.

Parameters

  • sensor: boolean

    True to set as a sensor, false to not be a sensor.

public SetUserData(data: any)

Set the user data. Use this to store your application specific data.

Parameters

  • data: any

    User provided data.

public TestPoint(p: b2Vec2): boolean

Test a point for containment in this fixture.

Parameters

  • p: b2Vec2

    Point to test against, in world coordinates.

Returns

boolean

True if the point is in this shape, otherwise false.