From 4d0618232b1d0c2a829ceb4c9417cd1eb64c0969 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 9 Jan 2020 00:43:38 +0000 Subject: [PATCH] Only render compound bounds --- src/physics/matter-js/World.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/physics/matter-js/World.js b/src/physics/matter-js/World.js index 3f952ac9f..4650dfff4 100644 --- a/src/physics/matter-js/World.js +++ b/src/physics/matter-js/World.js @@ -1569,6 +1569,8 @@ var World = new Class({ /** * Renders the bounds of an array of Bodies to the given Graphics instance. * + * If the body is a compound body, it will render the bounds for the parent compound. + * * The debug renderer calls this method if the `showBounds` config value is set. * * This method is used internally by the Matter Debug Renderer, but is also exposed publically should @@ -1596,19 +1598,33 @@ var World = new Class({ continue; } - var parts = body.parts; + var bounds = body.bounds; - for (var j = parts.length > 1 ? 1 : 0; j < parts.length; j++) + if (bounds) { - var part = parts[j]; - graphics.strokeRect( - part.bounds.min.x, - part.bounds.min.y, - part.bounds.max.x - part.bounds.min.x, - part.bounds.max.y - part.bounds.min.y + bounds.min.x, + bounds.min.y, + bounds.max.x - bounds.min.x, + bounds.max.y - bounds.min.y ); } + else + { + var parts = body.parts; + + for (var j = parts.length > 1 ? 1 : 0; j < parts.length; j++) + { + var part = parts[j]; + + graphics.strokeRect( + part.bounds.min.x, + part.bounds.min.y, + part.bounds.max.x - part.bounds.min.x, + part.bounds.max.y - part.bounds.min.y + ); + } + } } return this;