Physics.P2.Body#addPolygon()

addPolygon(options, points) → {boolean}

Reads a polygon shape path, and assembles convex shapes from that and puts them at proper offset points. The shape must be simple and without holes.
This function expects the x.y values to be given in pixels. If you want to provide them at p2 world scales then call Body.data.fromPolygon directly.

Parameters
Name Type Description
options object

An object containing the build options:

Properties
Name Type Argument Default Description
optimalDecomp boolean <optional>
false

Set to true if you need optimal decomposition. Warning: very slow for polygons with more than 10 vertices.

skipSimpleCheck boolean <optional>
false

Set to true if you already know that the path is not intersecting itself.

removeCollinearPoints boolean | number <optional>
false

Set to a number (angle threshold value) to remove collinear points, or false to keep all points.

points Array.<number> | number

An array of 2d vectors that form the convex or concave polygon.
Either [[0,0], [0,1],...] or a flat array of numbers that will be interpreted as [x,y, x,y, ...],
or the arguments passed can be flat x,y values e.g. setPolygon(options, x,y, x,y, x,y, ...) where x and y are numbers.

Returns
boolean -

True on success, else false.

Source code: physics/p2/Body.js (Line 1128)
doc_phaser
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.