Skip to content

Commit c296485

Browse files
committed
multiple circle shapes in a body with position
1 parent 21c0be4 commit c296485

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/physics/p2/Body.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,14 +1136,17 @@ Phaser.Physics.P2.Body.prototype = {
11361136

11371137
if (fixtureData.circle)
11381138
{
1139-
// A circle has unfortunately no position in p2. pretty useless.
1140-
var shape = new p2.Circle(this.world.pxm(fixtureData.circle.radius));
1141-
shape.collisionGroup = fixtureData.filter.categoryBits;
1142-
shape.collisionMask = fixtureData.filter.maskBits;
1143-
shape.sensor = fixtureData.isSensor;
1144-
1145-
this.data.addShape(shape);
1146-
generatedShapes.push(shape);
1139+
var shape = new p2.Circle(this.world.pxm(fixtureData.circle.radius))
1140+
shape.collisionGroup = fixtureData.filter.categoryBits
1141+
shape.collisionMask = fixtureData.filter.maskBits
1142+
shape.sensor = fixtureData.isSensor
1143+
1144+
var offset = p2.vec2.create();
1145+
offset[0] = this.world.pxmi(fixtureData.circle.position[0] - this.sprite.width/2)
1146+
offset[1] = this.world.pxmi(fixtureData.circle.position[1] - this.sprite.height/2)
1147+
1148+
this.data.addShape(shape, offset);
1149+
generatedShapes.push(shape)
11471150
}
11481151
else
11491152
{

src/physics/p2/BodyDebug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Phaser.Utils.extend(Phaser.Physics.P2.BodyDebug.prototype, {
120120

121121
if (child instanceof p2.Circle)
122122
{
123-
this.drawCircle(sprite, offset[0] * this.ppu, -offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
123+
this.drawCircle(sprite, offset[0] * this.ppu, offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
124124
}
125125
else if (child instanceof p2.Convex)
126126
{

0 commit comments

Comments
 (0)