Home Reference Source
public class | source

Polygon

Extends:

Body → Polygon

Direct Subclass:

Point

A polygon used to detect collisions

Constructor Summary

Public Constructor
public

constructor(x: Number, y: Number, points: Array<Number[]>, angle: Number, scale_x: Number, scale_y: Number, padding: Number)

Member Summary

Public Members
public

The angle of the body in radians

public

The scale of the body along the X axis

public

The scale of the body along the Y axis

Method Summary

Public Methods
public

draw(context: CanvasRenderingContext2D)

Draws the polygon to a CanvasRenderingContext2D's current path

public

setPoints(new_points: Array<Number[]>)

Sets the points making up the polygon.

Inherited Summary

From class Body
public static

Creates a Result used to collect the detailed results of a collision test

public

The amount to pad the bounding volume when testing for potential collisions

public

The X coordinate of the body

public

The Y coordinate of the body

public

collides(target: Circle | Polygon | Point, result: Result, aabb: Boolean): Boolean

Determines if the body is colliding with another body

public

Creates a Result used to collect the detailed results of a collision test

public

Returns a list of potential collisions

public

remove()

Removes the body from its current collision system

Public Constructors

public constructor(x: Number, y: Number, points: Array<Number[]>, angle: Number, scale_x: Number, scale_y: Number, padding: Number) source

Override:

Body#constructor

Params:

NameTypeAttributeDescription
x Number
  • optional
  • default: 0

The starting X coordinate

y Number
  • optional
  • default: 0

The starting Y coordinate

points Array<Number[]>
  • optional
  • default: []

An array of coordinate pairs making up the polygon - [[x1, y1], [x2, y2], ...]

angle Number
  • optional
  • default: 0

The starting rotation in radians

scale_x Number
  • optional
  • default: 1

The starting scale along the X axis

scale_y Number
  • optional
  • default: 1

The starting scale long the Y axis

padding Number
  • optional
  • default: 0

The amount to pad the bounding volume when testing for potential collisions

Public Members

public angle: Number source

The angle of the body in radians

public scale_x: Number source

The scale of the body along the X axis

public scale_y: Number source

The scale of the body along the Y axis

Public Methods

public draw(context: CanvasRenderingContext2D) source

Draws the polygon to a CanvasRenderingContext2D's current path

Params:

NameTypeAttributeDescription
context CanvasRenderingContext2D

The context to add the shape to

public setPoints(new_points: Array<Number[]>) source

Sets the points making up the polygon. It's important to use this function when changing the polygon's shape to ensure internal data is also updated.

Params:

NameTypeAttributeDescription
new_points Array<Number[]>

An array of coordinate pairs making up the polygon - [[x1, y1], [x2, y2], ...]