Skip to content

Commit 64c12a9

Browse files
committed
Added showBodyPosition config option
1 parent aa32235 commit 64c12a9

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/physics/matter-js/World.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ var World = new Class({
244244
showBody: GetFastValue(debugConfig, 'showBody', true),
245245
showStaticBody: GetFastValue(debugConfig, 'showStaticBody', true),
246246
showSleeping: GetFastValue(debugConfig, 'showSleeping', false),
247+
showBodyPosition: GetFastValue(debugConfig, 'showBodyPosition', true),
247248
showJoint: GetFastValue(debugConfig, 'showJoint', true),
248249
showInternalEdges: GetFastValue(debugConfig, 'showInternalEdges', false),
249250
showConvexHulls: GetFastValue(debugConfig, 'showConvexHulls', false),
@@ -264,6 +265,9 @@ var World = new Class({
264265
sleepFillColor: GetFastValue(debugConfig, 'sleepFillColor', 0x464646),
265266
sleepLineColor: GetFastValue(debugConfig, 'sleepLineColor', 0x999a99),
266267

268+
positionSize: GetFastValue(debugConfig, 'positionSize', 4),
269+
positionColor: GetFastValue(debugConfig, 'positionColor', 0xe042da),
270+
267271
jointColor: GetFastValue(debugConfig, 'jointColor', 0xe0e042),
268272
jointLineOpacity: GetFastValue(debugConfig, 'jointLineOpacity', 1),
269273
jointLineThickness: GetFastValue(debugConfig, 'jointLineThickness', 2),
@@ -1411,21 +1415,12 @@ var World = new Class({
14111415
if (fillColor === undefined) { fillColor = null; }
14121416
if (fillOpacity === undefined) { fillOpacity = null; }
14131417

1418+
var config = this.debugConfig;
1419+
14141420
// Handle compound parts
14151421
var parts = body.parts;
14161422
var partsLength = parts.length;
14171423

1418-
/*
1419-
if (!body.isStatic)
1420-
{
1421-
var w = body.bounds.max.x - body.bounds.min.x;
1422-
var h = body.bounds.max.y - body.bounds.min.y;
1423-
1424-
graphics.fillStyle(0x6d6d6d, 0.3);
1425-
graphics.fillRect(body.bounds.min.x, body.bounds.min.y, w, h);
1426-
}
1427-
*/
1428-
14291424
for (var k = (partsLength > 1) ? 1 : 0; k < partsLength; k++)
14301425
{
14311426
var part = parts[k];
@@ -1498,13 +1493,14 @@ var World = new Class({
14981493
}
14991494
}
15001495

1501-
if (!body.isStatic)
1496+
if (config.showBodyPosition && !body.isStatic)
15021497
{
15031498
var px = body.position.x;
15041499
var py = body.position.y;
1500+
var hs = Math.ceil(config.positionSize / 2);
15051501

1506-
graphics.fillStyle(0xff00ff, 1);
1507-
graphics.fillRect(px - 3, py - 3, 6, 6);
1502+
graphics.fillStyle(config.positionColor, 1);
1503+
graphics.fillRect(px - hs, py - hs, config.positionSize, config.positionSize);
15081504
}
15091505

15101506
return this;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* @property {boolean} [showJoint=true] - Render all world constraints to the Graphics object?
99
* @property {boolean} [showInternalEdges=false] - When rendering bodies, render the internal edges as well?
1010
* @property {boolean} [showConvexHulls=false] - When rendering polygon bodies, render the convex hull as well?
11+
* @property {boolean} [showBodyPosition=true] - Render the position of non-static bodies?
1112
* @property {boolean} [renderFill=false] - Render the bodies using a fill color.
1213
* @property {boolean} [renderLine=true] - Render the bodies using a line stroke.
1314
* @property {number} [fillColor=0x106909] - The color value of the fill when rendering dynamic bodies.
@@ -20,6 +21,8 @@
2021
* @property {number} [staticBodySleepOpacity=0.7] - The amount to multiply the opacity of sleeping static bodies by.
2122
* @property {number} [sleepFillColor=0x464646] - The color value of the fill when rendering sleeping dynamic bodies.
2223
* @property {number} [sleepLineColor=0x999a99] - The color value of the line stroke when rendering sleeping dynamic bodies.
24+
* @property {number} [positionSize=4] - The size of the rectangle drawn when rendering the body position.
25+
* @property {number} [positionColor=0xe042da] - The color value of the rectangle drawn when rendering the body position.
2326
* @property {number} [jointColor=0xe0e042] - The color value of joints when `showJoint` is set.
2427
* @property {number} [jointLineOpacity=1] - The line opacity when rendering joints, a value between 0 and 1.
2528
* @property {number} [jointLineThickness=2] - The line thickness when rendering joints.

0 commit comments

Comments
 (0)