Skip to content

Commit e07513b

Browse files
committed
Small restructure
1 parent 4e53d74 commit e07513b

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

  • src/physics/matter-js/lib/body

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples).
77
* @class Body
8-
*/
8+
*/
99

1010
var Body = {};
1111

@@ -190,19 +190,6 @@ var Axes = require('../geometry/Axes');
190190
});
191191

192192
var bounds = body.bounds;
193-
var centerOfMass = body.centerOfMass;
194-
var centerOffset = body.centerOffset;
195-
196-
Bounds.update(bounds, body.vertices, body.velocity);
197-
198-
var bodyWidth = bounds.max.x - bounds.min.x;
199-
var bodyHeight = bounds.max.y - bounds.min.y;
200-
201-
centerOfMass.x = -(bounds.min.x - body.position.x) / bodyWidth;
202-
centerOfMass.y = -(bounds.min.y - body.position.y) / bodyHeight;
203-
204-
centerOffset.x = body.position.x;
205-
centerOffset.y = body.position.y;
206193

207194
Vertices.rotate(body.vertices, body.angle, body.position);
208195
Axes.rotate(body.axes, body.angle);
@@ -215,6 +202,18 @@ var Axes = require('../geometry/Axes');
215202
mass: options.mass || body.mass,
216203
inertia: options.inertia || body.inertia
217204
});
205+
206+
var centerOfMass = body.centerOfMass;
207+
var centerOffset = body.centerOffset;
208+
209+
var bodyWidth = bounds.max.x - bounds.min.x;
210+
var bodyHeight = bounds.max.y - bounds.min.y;
211+
212+
centerOfMass.x = -(bounds.min.x - body.position.x) / bodyWidth;
213+
centerOfMass.y = -(bounds.min.y - body.position.y) / bodyHeight;
214+
215+
centerOffset.x = body.position.x;
216+
centerOffset.y = body.position.y;
218217
};
219218

220219
/**
@@ -1299,6 +1298,15 @@ var Axes = require('../geometry/Axes');
12991298
* @default { x: 0, y: 0 }
13001299
*/
13011300

1301+
/**
1302+
* The center of the body in pixel values.
1303+
* Used by Phaser for texture aligment.
1304+
*
1305+
* @property centerOffset
1306+
* @type vector
1307+
* @default { x: 0, y: 0 }
1308+
*/
1309+
13021310
/**
13031311
* Will this Body ignore World gravity during the Engine update?
13041312
*

0 commit comments

Comments
 (0)