Added in Circle to the Ninja physics system.

This commit is contained in:
photonstorm
2014-03-06 07:18:59 +00:00
parent 3e93f24583
commit e97a207816
4 changed files with 2657 additions and 5 deletions
+4 -2
View File
@@ -15,11 +15,13 @@
* @param {Phaser.Sprite} sprite - The Sprite object this physics body belongs to.
* @param {number} [type=1] - The type of Ninja shape to create. 1 = AABB, 2 = Circle or 3 = Tile.
* @param {number} [id=1] - If this body is using a Tile shape, you can set the Tile id here, i.e. Phaser.Physics.Ninja.Tile.SLOPE_45DEGpn, Phaser.Physics.Ninja.Tile.CONVEXpp, etc.
* @param {number} [radius=16] - If this body is using a Circle shape this controls the radius.
*/
Phaser.Physics.Ninja.Body = function (system, sprite, type, id) {
Phaser.Physics.Ninja.Body = function (system, sprite, type, id, radius) {
if (typeof type === 'undefined') { type = 1; }
if (typeof id === 'undefined') { id = 1; }
if (typeof radius === 'undefined') { radius = 16; }
/**
* @property {Phaser.Sprite} sprite - Reference to the parent Sprite.
@@ -68,7 +70,7 @@ Phaser.Physics.Ninja.Body = function (system, sprite, type, id) {
}
else if (type === 2)
{
this.circle = new Phaser.Physics.Ninja.Circle(system, sprite.x, sprite.y, sprite.width, sprite.height);
this.circle = new Phaser.Physics.Ninja.Circle(system, sprite.x, sprite.y, radius);
this.shape = this.circle;
}
else if (type === 3)
File diff suppressed because it is too large Load Diff
+10 -2
View File
@@ -124,7 +124,7 @@ Phaser.Physics.Ninja.prototype = {
{
if (object[i].body === null)
{
object[i].body = new Phaser.Physics.Ninja.Body(this, object[i], type, id);
object[i].body = new Phaser.Physics.Ninja.Body(this, object[i], type, id, radius);
object[i].anchor.set(0.5);
}
}
@@ -442,7 +442,15 @@ Phaser.Physics.Ninja.prototype = {
return body2.aabb.collideAABBVsTile(body1.tile);
}
// circles next
if (body1.circle && body2.tile)
{
return body1.circle.collideCircleVsTile(body2.tile);
}
if (body1.tile && body2.circle)
{
return body2.circle.collideCircleVsTile(body1.tile);
}
}