Skip to content

Commit 97410f8

Browse files
committed
add debug drawing for p2 capsule shape
1 parent 23d31ff commit 97410f8

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/physics/p2/BodyDebug.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Phaser.Utils.extend(Phaser.Physics.P2.BodyDebug.prototype, {
111111
{
112112
this.drawCircle(sprite, offset[0] * this.ppu, offset[1] * this.ppu, angle, child.radius * this.ppu, color, lw);
113113
}
114+
else if (child instanceof p2.Capsule) {
115+
this.drawCapsule(sprite, offset[0] * this.ppu, offset[1] * this.ppu, angle, child.length * this.ppu, child.radius * this.ppu, lineColor, color, lw);
116+
}
114117
else if (child instanceof p2.Plane)
115118
{
116119
this.drawPlane(sprite, offset[0] * this.ppu, -offset[1] * this.ppu, color, lineColor, lw * 5, lw * 10, lw * 10, this.ppu * 100, angle);
@@ -360,6 +363,40 @@ Phaser.Utils.extend(Phaser.Physics.P2.BodyDebug.prototype, {
360363

361364
},
362365

366+
drawCapsule: function(g, x, y, angle, len, radius, color, fillColor, lineWidth) {
367+
368+
if (typeof lineWidth === 'undefined') { lineWidth = 1; }
369+
if (typeof color === 'undefined') { color = 0x000000 }
370+
371+
g.lineStyle(lineWidth, color, 1);
372+
373+
// Draw circles at ends
374+
var c = Math.cos(angle);
375+
var s = Math.sin(angle);
376+
377+
g.beginFill(fillColor, 1);
378+
g.drawCircle(-len/2*c + x, -len/2*s + y, -radius * 2);
379+
g.drawCircle( len/2*c + x, len/2*s + y, -radius * 2);
380+
g.endFill();
381+
382+
// Draw rectangle
383+
g.lineStyle(lineWidth, color, 0);
384+
g.beginFill(fillColor, 1);
385+
g.moveTo(-len/2*c + radius*s + x, -len/2*s + radius*c + y);
386+
g.lineTo( len/2*c + radius*s + x, len/2*s + radius*c + y);
387+
g.lineTo( len/2*c - radius*s + x, len/2*s - radius*c + y);
388+
g.lineTo(-len/2*c - radius*s + x, -len/2*s - radius*c + y);
389+
g.endFill();
390+
391+
// Draw lines in between
392+
g.lineStyle(lineWidth, color, 1);
393+
g.moveTo(-len/2*c + radius*s + x, -len/2*s + radius*c + y);
394+
g.lineTo( len/2*c + radius*s + x, len/2*s + radius*c + y);
395+
g.moveTo(-len/2*c - radius*s + x, -len/2*s - radius*c + y);
396+
g.lineTo( len/2*c - radius*s + x, len/2*s - radius*c + y);
397+
398+
},
399+
363400
/**
364401
* Picks a random pastel color.
365402
*

0 commit comments

Comments
 (0)