Namespace: PhysicsJSONParser

Phaser.Physics.Matter. PhysicsJSONParser

Creates a body using the supplied physics data, as provided by a JSON file.

The data file should be loaded as JSON:

preload ()
  this.load.json('ninjas', 'assets/ninjas.json);

create ()
  const ninjaShapes = this.cache.json.get('ninjas');

  this.matter.add.fromJSON(400, 300, ninjaShapes.shinobi);

Do not pass the entire JSON file to this method, but instead pass one of the shapes contained within it.

If you pas in an options object, any settings in there will override those in the config object.

The structure of the JSON file is as follows:

  'generator_info': // The name of the application that created the JSON data
  'shapeName': {
    'type': // The type of body
    'label': // Optional body label
    'vertices': // An array, or an array of arrays, containing the vertex data in x/y object pairs

At the time of writing, only the Phaser Physics Tracer App exports in this format.

Since: 3.22.0
Source: src/physics/matter-js/PhysicsJSONParser.js (Line 10)


<static> parseBody(x, y, config [, options])

Parses a body element from the given JSON data.

Name Type Argument Description
x number

The horizontal world location of the body.

y number

The vertical world location of the body.

config object

The body configuration data.

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

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

Since: 3.22.0
Source: src/physics/matter-js/PhysicsJSONParser.js (Line 53)

A Matter JS Body.