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

Polygon Shape

A Subclass of Shape that allows the Fixture to have the geometry of a polygon.

For more information, see: Shape documentation page

New

Returns a new instance of the PolygonShape class:

polygon_shape = PolygonShape.new box: [100, 100]

polygon_shape = PolygonShape.new vertices: [[0, 0], [50, 50], [100, 100]]

polygon_shape = PolygonShape.new box: [100, 100],
                                                              center: [50, 50],
                                                              angle: 60
Watch out!

The minimum number of vertices in the PolygonShape is three and the maximum is eight.

Vertices Count

Returns the number of vertices in the Polygon Shape:

polygon_shape = PolygonShape.new vertices: [[0, 0], [50, 50], [100, 100]]

# The following is 3
polygon_shape.vertices_count

Centroid

Gets the Polygon Shape centroid:

centroid = polygon_shape.centroid

p "The Polygon Shape centroid is: #{centroid}"

Metric Centroid

Gets the Polygon Shape centroid in Metric coordinates.

Vertices

Retrieves the vertices that composes the Polygon Shape:

polygon_shape.vertices.each do |vertex|
    p "The vertex is: #{vertex.x}, #{vertex.y}"
end
More intel!

Each vertex returned is a instance of a Point.

Metric Vertices

Retrieves the vertices in Metric coordinates that composes the Polygon Shape.

Normals

Gets the Polygon Shape's normals:

polygon_shape.normals.each do |normal|
    p "The normal is: #{normal.x}, #{normal.y}"
end
More intel!

Each normal returned is a instance of a Point.

Metric Normals

Gets the Polygon Shape's normals in Metric coordinates.

Vertex by Index

Retrieves a Polygon Shape vertex by its index:

vertex = polygon_shape.vertex_by_index 0

p "The vertex is: #{vertex.x}, #{vertex.y}"