Skip to content

Commit 77b86f4

Browse files
committed
support for debug rendering ninja AABB and circle bodies
1 parent da822ab commit 77b86f4

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/physics/ninja/Body.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,56 @@ Object.defineProperty(Phaser.Physics.Ninja.Body.prototype, "angle", {
546546

547547
});
548548

549+
/**
550+
* Render Sprite's Body.
551+
*
552+
* @method Phaser.Physics.Ninja.Body#render
553+
* @param {object} context - The context to render to.
554+
* @param {Phaser.Physics.Ninja.Body} body - The Body to render.
555+
* @param {string} [color='rgba(0,255,0,0.4)'] - color of the debug shape to be rendered. (format is css color string).
556+
* @param {boolean} [filled=true] - Render the shape as a filled (default, true) or a stroked (false)
557+
*/
558+
Phaser.Physics.Ninja.Body.render = function(context, body, color, filled) {
559+
color = color || 'rgba(0,255,0,0.4)';
560+
561+
if (typeof filled === 'undefined')
562+
{
563+
filled = true;
564+
}
565+
566+
if (body.aabb)
567+
{
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+
}
581+
}
582+
else if (body.circle)
583+
{
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+
}
600+
}
601+
};

src/utils/Debug.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ Phaser.Utils.Debug.prototype = {
688688
},
689689

690690
/**
691-
* Render a Sprites Physics body if it has one set. Note this only works for Arcade Physics.
691+
* Render a Sprites Physics body if it has one set. Note this only works for Arcade and
692+
* Ninja (AABB, circle only) Physics.
692693
* To display a P2 body you should enable debug mode on the body when creating it.
693694
*
694695
* @method Phaser.Utils.Debug#body
@@ -706,6 +707,12 @@ Phaser.Utils.Debug.prototype = {
706707
Phaser.Physics.Arcade.Body.render(this.context, sprite.body, color, filled);
707708
this.stop();
708709
}
710+
else if (sprite.body.type === Phaser.Physics.NINJA)
711+
{
712+
this.start();
713+
Phaser.Physics.Ninja.Body.render(this.context, sprite.body, color, filled);
714+
this.stop();
715+
}
709716
}
710717

711718
},

0 commit comments

Comments
 (0)