Skip to content

Commit fd45182

Browse files
committed
Debug drawing now happens after collision solver.
1 parent 48db06f commit fd45182

2 files changed

Lines changed: 43 additions & 27 deletions

File tree

v3/src/physics/impact/Body.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var Body = new Class({
8989
this.collides = COLLIDES.NEVER;
9090
},
9191

92-
update: function (delta, drawDebug)
92+
update: function (delta)
9393
{
9494
var pos = this.pos;
9595

@@ -119,30 +119,35 @@ var Body = new Class({
119119
go.y = (pos.y - this.offset.y) + go.displayOriginY * go.scaleY;
120120
}
121121

122-
if (drawDebug)
122+
if (this.updateCallback)
123123
{
124-
var graphic = this.world.debugGraphic;
125-
126-
if (this.debugShowBody)
127-
{
128-
graphic.lineStyle(1, this.debugBodyColor, 1);
129-
graphic.strokeRect(pos.x, pos.y, this.size.x, this.size.y);
130-
}
131-
132-
if (this.debugShowVelocity)
133-
{
134-
var x = pos.x + this.size.x / 2;
135-
var y = pos.y + this.size.y / 2;
136-
137-
graphic.lineStyle(1, this.world.defaults.velocityDebugColor, 1);
138-
graphic.lineBetween(x, y, x + this.vel.x, y + this.vel.y);
139-
}
124+
this.updateCallback(this);
140125
}
126+
},
141127

142-
if (this.updateCallback)
128+
drawDebug: function (graphic)
129+
{
130+
var pos = this.pos;
131+
132+
if (this.debugShowBody)
143133
{
144-
this.updateCallback(this);
134+
graphic.lineStyle(1, this.debugBodyColor, 1);
135+
graphic.strokeRect(pos.x, pos.y, this.size.x, this.size.y);
145136
}
137+
138+
if (this.debugShowVelocity)
139+
{
140+
var x = pos.x + this.size.x / 2;
141+
var y = pos.y + this.size.y / 2;
142+
143+
graphic.lineStyle(1, this.world.defaults.velocityDebugColor, 1);
144+
graphic.lineBetween(x, y, x + this.vel.x, y + this.vel.y);
145+
}
146+
},
147+
148+
willDrawDebug: function ()
149+
{
150+
return (this.debugShowBody || this.debugShowVelocity);
146151
},
147152

148153
skipHash: function ()

v3/src/physics/impact/World.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,14 @@ var World = new Class({
226226
var len = bodies.length;
227227
var hash = {};
228228
var size = this.cellSize;
229-
var debug = this.drawDebug;
230-
231-
if (debug)
232-
{
233-
this.debugGraphic.clear();
234-
}
235229

236230
for (i = 0; i < len; i++)
237231
{
238232
body = bodies[i];
239233

240234
if (body.enabled)
241235
{
242-
body.update(this.delta, debug);
236+
body.update(this.delta);
243237
}
244238
}
245239

@@ -254,6 +248,23 @@ var World = new Class({
254248
this.checkHash(body, hash, size);
255249
}
256250
}
251+
252+
if (this.drawDebug)
253+
{
254+
var graphics = this.debugGraphic;
255+
256+
graphics.clear();
257+
258+
for (i = 0; i < len; i++)
259+
{
260+
body = bodies[i];
261+
262+
if (body.willDrawDebug())
263+
{
264+
body.drawDebug(graphics);
265+
}
266+
}
267+
}
257268
},
258269

259270
// Check the body against the spatial hash

0 commit comments

Comments
 (0)