Skip to content

extractCollisionShapes

extractCollisionShapes(map, objectLayerName?): TilemapColliderConfig[]

Defined in: tilemap/src/colliders.ts:36

Extract physics-agnostic collision shapes from object layers.

  • Rectangle objects -> RectColliderConfig
  • Tile objects (a gid is set) -> RectColliderConfig over the tile’s box, like any rectangle: a MapObject’s x/y is its top-left corner whatever the corner Tiled anchored it on
  • Ellipse objects (width === height) -> CircleColliderConfig
  • Ellipse objects (width !== height) -> PolygonColliderConfig sampling the ellipse outline (Rapier has no ellipse primitive; the ring is convex, so the physics-side convex hull reproduces it exactly)
  • Capsule objects -> CapsuleColliderConfig oriented along the longer axis
  • Polygon objects -> PolylineColliderConfig with the closing edge appended (Tiled polygons are closed outlines and may be concave; static-only)
  • Polyline objects -> PolylineColliderConfig verbatim (open chain)
  • Point objects -> skipped (not collision shapes)

Object rotation (degrees in Tiled, pivoting on the object’s position) is honored for every shape: vertex-based shapes are rotated here, circles get their center shifted, and rect/capsule configs carry rotation in radians.

TilemapData

Generic TilemapData.

string

Optional: only extract from this layer.

TilemapColliderConfig[]