@@ -244,12 +244,26 @@ 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 ) ,
247+ showPositions : GetFastValue ( debugConfig , 'showPositions ' , true ) ,
248248 showJoint : GetFastValue ( debugConfig , 'showJoint' , true ) ,
249249 showInternalEdges : GetFastValue ( debugConfig , 'showInternalEdges' , false ) ,
250250 showConvexHulls : GetFastValue ( debugConfig , 'showConvexHulls' , false ) ,
251251 showSensors : GetFastValue ( debugConfig , 'showSensors' , true ) ,
252252
253+ showBroadphase : GetFastValue ( debugConfig , 'showBroadphase' , false ) ,
254+ broadphaseColor : GetFastValue ( debugConfig , 'broadphaseColor' , 0xffb400 ) ,
255+
256+ showBounds : true ,
257+ showVelocity : true ,
258+ showCollisions : true ,
259+ showSeparations : true ,
260+ showAxes : true ,
261+ showAngleIndicator : true ,
262+ showIds : true ,
263+ showShadows : true ,
264+ showVertexNumbers : true ,
265+ showMousePosition : true ,
266+
253267 renderFill : GetFastValue ( debugConfig , 'renderFill' , false ) ,
254268 renderLine : GetFastValue ( debugConfig , 'renderLine' , true ) ,
255269
@@ -1276,6 +1290,8 @@ var World = new Class({
12761290 postUpdate : function ( )
12771291 {
12781292 var config = this . debugConfig ;
1293+ var engine = this . engine ;
1294+ var graphics = this . debugGraphic ;
12791295
12801296 var showBody = config . showBody ;
12811297 var showStaticBody = config . showStaticBody ;
@@ -1288,6 +1304,11 @@ var World = new Class({
12881304
12891305 this . debugGraphic . clear ( ) ;
12901306
1307+ if ( config . showBroadphase && engine . broadphase . controller )
1308+ {
1309+ this . renderGrid ( engine . broadphase , graphics , config . broadphaseColor , 0.2 ) ;
1310+ }
1311+
12911312 var bodies = Composite . allBodies ( this . localWorld ) ;
12921313
12931314 this . renderBodies ( bodies ) ;
@@ -1298,6 +1319,50 @@ var World = new Class({
12981319 }
12991320 } ,
13001321
1322+ /**
1323+ * Renders the Engine Broadphase Controller Grid to the given Graphics instance.
1324+ *
1325+ * This method is used internally by the Matter Debug Renderer, but is also exposed publically should
1326+ * you wish to render the Grid to your own Graphics instance.
1327+ *
1328+ * @method Phaser.Physics.Matter.World#renderGrid
1329+ * @since 3.22.0
1330+ *
1331+ * @param {MatterJS.Grid } grid - The Matter Grid to be rendered.
1332+ * @param {Phaser.GameObjects.Graphics } graphics - The Graphics object to render to.
1333+ * @param {number } lineColor - The line color.
1334+ * @param {number } lineOpacity - The line opacity, between 0 and 1.
1335+ *
1336+ * @return {this } This Matter World instance for method chaining.
1337+ */
1338+ renderGrid : function ( grid , graphics , lineColor , lineOpacity )
1339+ {
1340+ graphics . lineStyle ( 1 , lineColor , lineOpacity ) ;
1341+
1342+ var bucketKeys = Common . keys ( grid . buckets ) ;
1343+
1344+ for ( var i = 0 ; i < bucketKeys . length ; i ++ )
1345+ {
1346+ var bucketId = bucketKeys [ i ] ;
1347+
1348+ if ( grid . buckets [ bucketId ] . length < 2 )
1349+ {
1350+ continue ;
1351+ }
1352+
1353+ var region = bucketId . split ( / C | R / ) ;
1354+
1355+ graphics . strokeRect (
1356+ parseInt ( region [ 1 ] , 10 ) * grid . bucketWidth ,
1357+ parseInt ( region [ 2 ] , 10 ) * grid . bucketHeight ,
1358+ grid . bucketWidth ,
1359+ grid . bucketHeight
1360+ ) ;
1361+ }
1362+
1363+ return this ;
1364+ } ,
1365+
13011366 /**
13021367 * Renders the given array of Bodies to the debug graphics instance.
13031368 *
@@ -1515,7 +1580,7 @@ var World = new Class({
15151580 }
15161581 }
15171582
1518- if ( config . showBodyPosition && ! body . isStatic )
1583+ if ( config . showPositions && ! body . isStatic )
15191584 {
15201585 var px = body . position . x ;
15211586 var py = body . position . y ;
0 commit comments