Merge pull request #972 from psalaets/debug-rendering-ninja-aabb-and-circle

Debug rendering for Ninja aabb and circle
This commit is contained in:
Richard Davey 2014-07-07 10:26:37 +01:00
commit e9886ad84d
4 changed files with 85 additions and 3 deletions

View file

@ -1003,6 +1003,31 @@ Phaser.Physics.Ninja.AABB.prototype = {
destroy: function() {
this.body = null;
this.system = null;
}
},
/**
* Render this AABB for debugging purposes.
*
* @method Phaser.Physics.Ninja.AABB#render
* @param {object} context - The context to render to.
* @param {number} xOffset - X offset from AABB's position to render at.
* @param {number} yOffset - Y offset from AABB's position to render at.
* @param {string} color - color of the debug shape to be rendered. (format is css color string).
* @param {boolean} filled - Render the shape as solid (true) or hollow (false).
*/
render: function(context, xOffset, yOffset, color, filled) {
var left = this.pos.x - this.xw - xOffset;
var top = this.pos.y - this.yw - yOffset;
if (filled)
{
context.fillStyle = color;
context.fillRect(left, top, this.width, this.height);
}
else
{
context.strokeStyle = color;
context.strokeRect(left, top, this.width, this.height);
}
}
};

View file

@ -546,3 +546,25 @@ Object.defineProperty(Phaser.Physics.Ninja.Body.prototype, "angle", {
});
/**
* Render Sprite's Body.
*
* @method Phaser.Physics.Ninja.Body#render
* @param {object} context - The context to render to.
* @param {Phaser.Physics.Ninja.Body} body - The Body to render.
* @param {string} [color='rgba(0,255,0,0.4)'] - color of the debug shape to be rendered. (format is css color string).
* @param {boolean} [filled=true] - Render the shape as a filled (default, true) or a stroked (false)
*/
Phaser.Physics.Ninja.Body.render = function(context, body, color, filled) {
color = color || 'rgba(0,255,0,0.4)';
if (typeof filled === 'undefined')
{
filled = true;
}
if (body.aabb || body.circle)
{
body.shape.render(context, body.game.camera.x, body.game.camera.y, color, filled);
}
};

View file

@ -2619,6 +2619,34 @@ Phaser.Physics.Ninja.Circle.prototype = {
destroy: function() {
this.body = null;
this.system = null;
}
},
/**
* Render this circle for debugging purposes.
*
* @method Phaser.Physics.Ninja.Circle#render
* @param {object} context - The context to render to.
* @param {number} xOffset - X offset from circle's position to render at.
* @param {number} yOffset - Y offset from circle's position to render at.
* @param {string} color - color of the debug shape to be rendered. (format is css color string).
* @param {boolean} filled - Render the shape as solid (true) or hollow (false).
*/
render: function(context, xOffset, yOffset, color, filled) {
var x = this.pos.x - xOffset;
var y = this.pos.y - yOffset;
context.beginPath();
context.arc(x, y, this.radius, 0, 2 * Math.PI, false);
if (filled)
{
context.fillStyle = color;
context.fill();
}
else
{
context.strokeStyle = color;
context.stroke();
}
}
};

View file

@ -688,7 +688,8 @@ Phaser.Utils.Debug.prototype = {
},
/**
* Render a Sprites Physics body if it has one set. Note this only works for Arcade Physics.
* Render a Sprites Physics body if it has one set. Note this only works for Arcade and
* Ninja (AABB, circle only) Physics.
* To display a P2 body you should enable debug mode on the body when creating it.
*
* @method Phaser.Utils.Debug#body
@ -706,6 +707,12 @@ Phaser.Utils.Debug.prototype = {
Phaser.Physics.Arcade.Body.render(this.context, sprite.body, color, filled);
this.stop();
}
else if (sprite.body.type === Phaser.Physics.NINJA)
{
this.start();
Phaser.Physics.Ninja.Body.render(this.context, sprite.body, color, filled);
this.stop();
}
}
},