Phaser API Documentation

  Version: 
fromSVG(x, y, xml, [scale], [options], [addToWorld])

Description:

Creates a body using the path data from an SVG file.

SVG Parsing requires the pathseg polyfill from https://github.com/progers/pathseg

The SVG file should be loaded as XML, as this method requires the ability to extract the path data from it. I.e.:

preload ()
{
  this.load.xml('face', 'assets/face.svg);
}

create ()
{
  this.matter.add.fromSVG(400, 300, this.cache.xml.get('face'));
}

Parameters:

name type arguments Default description
x number

The X coordinate of the body.

y number

The Y coordinate of the body.

xml object

The SVG Path data.

scale number <optional> 1

Scale the vertices by this amount after creation.

options Phaser.Types.Physics.Matter.MatterBodyConfig <optional>

An optional Body configuration object that is used to set initial Body properties on creation.

addToWorld boolean <optional> true

Should the newly created body be immediately added to the World?

Returns:
Description:

A Matter JS Body.

Type:
  • MatterJS.BodyType
Since: 3.22.0