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

Shape

The Shape class provides the Fixture a geometry but also allow to perform some operations like ray casting, AABB or Mass computing or overlapping point tests.

This class cannot be initialized directly and must be used through any of the following subclasses: Chain, Circle, Edge or Polygon Shape.

For more information, see: Chain Shape documentation page.

For more information, see: Circle Shape documentation page.

For more information, see: Edge Shape documentation page.

For more information, see: Polygon Shape documentation page.

::CircleType

::EdgeType

::PolygonType

::ChainType

Constants that represent the Shape types.

Type

Gets the Shape type:

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

Child Count

Returns the number of sub-shapes contained into the Shape instance:

child_count = shape.child_count

p "The child count is: #{child_count}"

Radius

Retrieves the radius of the Shape's instance:

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

Metric Radius

Retrieves the radius in Metric coordinates of the Shape's instance.

Contains Point?

Returns if a point is contained into a Shape:

shape.contains_point? [100, 100]

Ray Cast

Casts a ray against the Shape instance:

shape.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 Shape's Sub-shapes should check for a intersection.

More intel!

For Circle, Polygon or Edge Shapes the child_index is zero, in the case of the Chain Shape is from zero to the number of segments minus one.

Compute AABB

Computes the Shape's AABB:

aabb = shape.compute_aabb child_index: 0

p "The shape's AABB is: #{aabb}"
More intel!

For Circle, Polygon or Edge Shapes the child_index is zero, in the case of the Chain Shape is from zero to the number of segments minus one.

Compute Mass

Computes the mass of the Shape based on a density:

mass = shape.compute_mass density: 1
More intel!

The density should be in kilograms per meter squared.