Matter JS - option list - Am I blind?

Viewed 2163

New to MatterJS.

In the example, theres is options to draw circle, rectangle, etc. Those options are like using Sprite, FillStyle...

I see no where in the documentation the list of options and values related to that.

Anyone can help?

Thanks.

3 Answers

From reading the source code of matter.js I found the defaults for options. Doesn't explain what each does but at least here's a list of them:

var defaults = {
  id: Common.nextId(),
  type: 'body',
  label: 'Body',
  parts: [],
  plugin: {},
  angle: 0,
  vertices: Vertices.fromPath('L 0 0 L 40 0 L 40 40 L 0 40'),
  position: { x: 0, y: 0 },
  force: { x: 0, y: 0 },
  torque: 0,
  positionImpulse: { x: 0, y: 0 },
  constraintImpulse: { x: 0, y: 0, angle: 0 },
  totalContacts: 0,
  speed: 0,
  angularSpeed: 0,
  velocity: { x: 0, y: 0 },
  angularVelocity: 0,
  isSensor: false,
  isStatic: false,
  isSleeping: false,
  motion: 0,
  sleepThreshold: 60,
  density: 0.001,
  restitution: 0,
  friction: 0.1,
  frictionStatic: 0.5,
  frictionAir: 0.01,
  collisionFilter: {
    category: 0x0001,
    mask: 0xFFFFFFFF,
    group: 0
  },
  slop: 0.05,
  timeScale: 1,
  render: {
    visible: true,
    opacity: 1,
    sprite: {
      xScale: 1,
      yScale: 1,
      xOffset: 0,
      yOffset: 0
    },
    lineWidth: 0
  }
};

As taras pointed out the object's properties are initialized from these options.

I think that in those examples, matter.js is handling the drawing of the shapes of the bodies itself through Render.bodies (inside matter.js file) and related functions.

In case anyone want to draw lines, circles or rectangles, they can access the canvas that matter.js uses, and draw them via lineTo, arc functions of canvas, I guess.

Related