Skip to content

Commit 0c15ef6

Browse files
committed
move shape specific debug rendering into the shapes
1 parent 77b86f4 commit 0c15ef6

3 files changed

Lines changed: 57 additions & 31 deletions

File tree

src/physics/ninja/AABB.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,31 @@ Phaser.Physics.Ninja.AABB.prototype = {
10031003
destroy: function() {
10041004
this.body = null;
10051005
this.system = null;
1006-
}
1006+
},
1007+
1008+
/**
1009+
* Render this AABB for debugging purposes.
1010+
*
1011+
* @method Phaser.Physics.Ninja.AABB#render
1012+
* @param {object} context - The context to render to.
1013+
* @param {number} xOffset - X offset from AABB's position to render at.
1014+
* @param {number} yOffset - Y offset from AABB's position to render at.
1015+
* @param {string} color - color of the debug shape to be rendered. (format is css color string).
1016+
* @param {boolean} filled - Render the shape as solid (true) or hollow (false).
1017+
*/
1018+
render: function(context, xOffset, yOffset, color, filled) {
1019+
var left = this.pos.x - this.xw - xOffset;
1020+
var top = this.pos.y - this.yw - yOffset;
10071021

1022+
if (filled)
1023+
{
1024+
context.fillStyle = color;
1025+
context.fillRect(left, top, this.width, this.height);
1026+
}
1027+
else
1028+
{
1029+
context.strokeStyle = color;
1030+
context.strokeRect(left, top, this.width, this.height);
1031+
}
1032+
}
10081033
};

src/physics/ninja/Body.js

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -565,37 +565,10 @@ Phaser.Physics.Ninja.Body.render = function(context, body, color, filled) {
565565

566566
if (body.aabb)
567567
{
568-
var left = body.x - (body.width / 2) - body.game.camera.x;
569-
var top = body.y - (body.height / 2) - body.game.camera.y;
570-
571-
if (filled)
572-
{
573-
context.fillStyle = color;
574-
context.fillRect(left, top, body.width, body.height);
575-
}
576-
else
577-
{
578-
context.strokeStyle = color;
579-
context.strokeRect(left, top, body.width, body.height);
580-
}
568+
body.aabb.render(context, body.game.camera.x, body.game.camera.y, color, filled);
581569
}
582570
else if (body.circle)
583571
{
584-
var x = body.x - body.game.camera.x;
585-
var y = body.y - body.game.camera.y;
586-
587-
context.beginPath();
588-
context.arc(x, y, body.circle.radius, 0, 2 * Math.PI, false);
589-
590-
if (filled)
591-
{
592-
context.fillStyle = color;
593-
context.fill();
594-
}
595-
else
596-
{
597-
context.strokeStyle = color;
598-
context.stroke();
599-
}
572+
body.circle.render(context, body.game.camera.x, body.game.camera.y, color, filled);
600573
}
601574
};

src/physics/ninja/Circle.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2619,6 +2619,34 @@ Phaser.Physics.Ninja.Circle.prototype = {
26192619
destroy: function() {
26202620
this.body = null;
26212621
this.system = null;
2622-
}
2622+
},
2623+
2624+
/**
2625+
* Render this circle for debugging purposes.
2626+
*
2627+
* @method Phaser.Physics.Ninja.Circle#render
2628+
* @param {object} context - The context to render to.
2629+
* @param {number} xOffset - X offset from circle's position to render at.
2630+
* @param {number} yOffset - Y offset from circle's position to render at.
2631+
* @param {string} color - color of the debug shape to be rendered. (format is css color string).
2632+
* @param {boolean} filled - Render the shape as solid (true) or hollow (false).
2633+
*/
2634+
render: function(context, xOffset, yOffset, color, filled) {
2635+
var x = this.pos.x - xOffset;
2636+
var y = this.pos.y - yOffset;
2637+
2638+
context.beginPath();
2639+
context.arc(x, y, this.radius, 0, 2 * Math.PI, false);
26232640

2641+
if (filled)
2642+
{
2643+
context.fillStyle = color;
2644+
context.fill();
2645+
}
2646+
else
2647+
{
2648+
context.strokeStyle = color;
2649+
context.stroke();
2650+
}
2651+
}
26242652
};

0 commit comments

Comments
 (0)