Skip to content

Commit 03e67e2

Browse files
committed
Added docs and Body level syncVerts property
1 parent 01fa4d2 commit 03e67e2

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
* `Body.setCentre` is a new method added to Matter that allows you to set the center of mass of a Body (please note the English spelling of this function.)
102102
* Bumped Matter Plugin versions to avoid console logs from Common.info and Common.warn.
103103
* `Vertices.calcOffset` is a new function that calculates the vert body position offset, used for keeping data in sync.
104-
* `Engine.syncVerts` is a new Engine config property that allows you to run a vert re-sync at the end of the Engine step. This can help massively if you find you've got verts drifting out of alignment with the body position when using pointer contraints, or high velocity environments. Uses the new `Engine._bodiesSync` function.
105-
* `Body.syncVerts` is a new function that will re-sync the vert positions with the body position. Called if `Engine.syncVerts` is set (which is now the default)
104+
* `Engine.syncVerts` is a new Engine config property that allows you to re-sync all the vertices ofa Body with the bodies position at the end of the Engine step. This can help massively if you find you've got verts drifting out of alignment with the body position when using pointer contraints, or high velocity environments. Uses the new `Engine._bodiesSync` function.
105+
* `Body.syncVerts` is a new function that will re-sync the vert positions with the body position. Called if `Engine.syncVerts` is `true` and if the Body has its `syncVerts` property set to `true`.
106106
* `Body.scale` is a new vector that holds the most recent scale values as passed to `Body.scale`.
107107
* `Matter.Bodies.flagCoincidentParts` is a new function that will flags all internal edges (coincident parts) on an array of body parts. This was previously part of the `fromVertices` function, but has been made external for outside use.
108108
* `PhysicsEditorParser.parseVertices` now uses `Bodies.flagCoincidentParts` to avoid duplicating code.

src/physics/matter-js/lib/body/Body.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var Axes = require('../geometry/Axes');
4141
type: 'body',
4242
label: 'Body',
4343
gameObject: null, // custom Phaser property
44+
syncVerts: false, // custom Phaser property
4445
parts: [],
4546
plugin: {},
4647
angle: 0,
@@ -904,6 +905,18 @@ var Axes = require('../geometry/Axes');
904905
* @type vector[]
905906
*/
906907

908+
/**
909+
* If `Engine.syncVerts` has been enabled in the Matter config, then this Body will have its vertices
910+
* resynced with its body position at the end of the `Engine.update` step. This is important if you are
911+
* moving a Body around at high speed and colliding with static objects, or are using pointer constraints
912+
* and allowing a Body to be dragged around, as Matter can often lose sync between the body position and
913+
* its vertices under these situations.
914+
*
915+
* @property syncVerts
916+
* @type boolean
917+
* @default false
918+
*/
919+
907920
/**
908921
* A `Vector` that specifies the current world-space position of the body.
909922
*

src/physics/matter-js/lib/core/Engine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var Body = require('../body/Body');
4949
velocityIterations: 4,
5050
constraintIterations: 2,
5151
enableSleeping: false,
52-
syncVerts: true,
52+
syncVerts: true, // custom Phaser property
5353
events: [],
5454
plugin: {},
5555
timing: {
@@ -338,7 +338,7 @@ var Body = require('../body/Body');
338338
{
339339
var body = bodies[i];
340340

341-
if (body.isStatic || body.isSleeping)
341+
if (!body.syncVerts || body.isStatic || body.isSleeping)
342342
{
343343
continue;
344344
}

src/physics/matter-js/typedefs/MatterWorldConfig.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)