Documentation

WHAT WE GOT

AABB
Physics Environment

Animation
Actions & Animations

Array
Support Classes

Audio
Sounds & Music

Audio Effect
Sounds & Music

Background Audio
Sounds & Music

Bezier
Actions & Animations

Blink
Actions & Animations

Body
Physics Environment

Callback
Actions & Animations

Chain Shape
Physics Environment

Circle Shape
Physics Environment

Color
Support Classes

Delay
Actions & Animations

Device
Support Classes

Director
Essentials

Ease
Actions & Animations

Edge Shape
Physics Environment

Event
Support Classes

Fade
Actions & Animations

Filter
Physics Environment

Fixture
Physics Environment

Jump
Actions & Animations

Label
User Interface

Layer
Essentials

Layer Color
Essentials

Liquid
Actions & Animations

Mass Data
Physics Environment

Menu
User Interface

Menu Image
User Interface

Menu Label
User Interface

Move
Actions & Animations

Numeric
Support Clases

Object Layer
Tiled Maps

Physics Sprite
Physics Environment

Place
Actions & Animations

Point
Support Classes

Polygon Shape
Physics Environment

Repeat
Actions & Animations

Rotate
Actions & Animations

Scale
Actions & Animations

Scene
Essentials

Screen
Support Classes

Sequence
Actions & Animations

Shape
Physics Environment

Shuffle
Actions & Animations

Size
Support Classes

Skew
Actions & Animations

Spawn
Actions & Animations

Split
Actions & Animations

Sprite
Essentials

Sprite Batch
Essentials

Sprite Frame Cache
Essentials

Tile Layer
Tiled Maps

Tile Map
Tiled Maps

Tile Set
Tiled Maps

Tint
Actions & Animations

Touch
Support Classes

Turn
Actions & Animations

Twirl
Actions & Animations

Visibility
Actions & Animations

Wave
Actions & Animations

Wiggle
Actions & Animations

World
Physics Environment

PHYSICS ENVIRONMENT

Fixture

The Fixture class provides the following physics properties to the Body class: Shape, Density, Friction and Restitution. Also they contain all the necessary information to simulate or not a collision.

Watch out!

The Fixture class cannot be instantiated by itself, it is required to be created using the Body's new_fixture method.

::CircleType

::EdgeType

::PolygonType

::ChainType

Constants that represent the types of the fixtures according to its inner shape.

::new

Using the Body's new fixture method we can create a new instance of a Fixture:

body.new_fixture do
    polygon_fixture box: [16, 16],
                              friction: 1,
                              restitution: 0.5,
                              density: 0.0,
                              is_sensor: true
end

fixture = body.fixtures[0]

In the previous scenario a new Fixture is created with a Polygon shape, friction of 1.0, restitution of 0.5 and density of 0.0.

For more information, see: Body documentation page.

Type

Gets the Fixture type:

fixture = body.fixtures[0]

p "The fixture type is: #{fixture.type}"

Body

Gets the Fixture's body:

body = world.new_body position: [100, 100], type: Body::Dynamic do
      polygon_fixture box: [16, 16],
                               density: 1.0,
                               friction: 1.0,
                               restitution: 1.0
end

fixture = body.fixtures[0]

# The following is true
fixture.body == body

Shape

Returns the Shape of the Fixture:

fixture = body.fixtures[0]

p "The fixture shape is: #{fixture.shape}"

Density

Gets or Sets the Fixture's density:

fixture.density = 0.3

p "The fixture density is: #{fixture.density}"

Friction

Retrieves or updates the friction of the Fixture:

fixture.friction = 1.0

p "The fixture friction is: #{fixture.friction}"

Restitution

Gets or Sets the Fixture's restitution:

fixture.restitution = 0.0

p "The fixture restitution is: #{fixture.restitution}"

Sensor

Sensor?

Retrieves or updates if the Fixture is a sensor:

fixture.sensor = false

p "The fixture is a sensor: #{fixture.sensor?}"

Mass Data

Retrieves the Fixture mass data:

fixture = body.fixtures[0]

p "The fixture mass data is: #{fixture.mass_data}"

Contains Point?

Determinate if the Fixture contains a point:

body = world.new_body position: [100, 100], type: Body::Dynamic do
      polygon_fixture box: [16, 16],
                               density: 1.0,
                               friction: 1.0,
                               restitution: 1.0
end

fixture = body.fixtures[0]

# The following is true
fixture.contains_point? [100, 100]

Refilter

Enables a collision that was previously disabled by the when collide method of the World's class:

fixture = body.fixtures[0]

fixture.refilter

AABB

Retrieves the AABB of the Fixture:

fixture = body.fixtures[0]

aabb = fixture.aabb child_index: 0

p "The fixture AABB is: #{aabb}"
More intel!

For circle, polygon or edge Fixtures the child_index is zero, in the case of the chain Fixture is from zero to the number of segments minus one.

Ray Cast

Casts a ray against the Fixture shape:

fixture.ray_cast first_point: [10, 10],
                     second_point: [20, 20],
                     maximum_fraction: 2,
                     child_index: 0 do |hits, normal, fraction|

                     end

Options

first_point: - Point Required
The initial point of the ray.

second_point: - Point Required
The final point of the ray.

maximum_fraction: - Float Required
How far the ray should go to check for a intersection.

The total distance will be a product of the maximum fraction and the distance between the first and second point, in other words: if the double of distance between the first and second point needed to be checked, the maximum fraction should be two.

child_index: - Integer Required
In which of the Fixture's Sub-shapes should check for a intersection.

More intel!

For circle, polygon or edge Fixtures the child_index is zero, in the case of the chain Fixture is from zero to the number of segments minus one.

Block Parameters

hits - Boolean
If the ray found a intersection.

normal - Point
Normal of the ray at the point of intersection.

fraction - Float
How far the ray go to found a intersection.

For more information, see: iforce2d Ray casting