Skip to content

Commit

Permalink
Merge pull request #1170 from starwed/debug-layer-fix
Browse files Browse the repository at this point in the history
Fix for debugging non-renderable components
  • Loading branch information
starwed authored Jan 15, 2018
2 parents c905770 + 2dc4b30 commit 08a59c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions playgrounds/parallax.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
Crafty.e("Background, Bar, Collision, WiredHitBox").color("blue").attr({x: 100*i, y: 10, z: 30});
Crafty.e("Midground, Bar, Collision, WiredHitBox").color("purple").attr({x: 100*i, y: 20, z: 30});
Crafty.e("Foreground, Bar, Collision, WiredHitBox").color("yellow").attr({x: 100*i, y: 30, z: 10});

// A hitbox not attached to a renderable entity should track the default layer
Crafty.e("2D, Collision, WiredHitBox").debugStroke("green").attr({x: 100*i, y: 40, z: 100, h: 100, w: 31});
Crafty.e("ActionLayer, Bar").color("brown").attr({x: 100*i, y: 40, z: 100});

}

// Some text that shows the viewport's current position, and sits in the UI layer
Expand Down
13 changes: 9 additions & 4 deletions src/debug/debug-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,17 @@ Crafty.DebugCanvas = {
current = q[i];

// If necessary, update the view transform to match the current entities layer
if (lastLayer !== current._drawlayer){
view = current._drawLayer._viewportRect();
ctx.setTransform(view._scale, 0, 0, view._scale, Math.round(-view._x*view._scale), Math.round(-view._y*view._scale));
// If the current entity has no layer, switch back to the viewport's transform
if (lastLayer !== current._drawLayer){
if (current._drawLayer) {
view = current._drawLayer._viewportRect();
ctx.setTransform(view._scale, 0, 0, view._scale, Math.round(-view._x*view._scale), Math.round(-view._y*view._scale));
} else {
view = Crafty.viewport;
ctx.setTransform(view._scale, 0, 0, view._scale, Math.round(view._x*view._scale), Math.round(view._y*view._scale));
}
lastLayer = current._drawLayer;
}

current.debugDraw(ctx);
}

Expand Down

0 comments on commit 08a59c7

Please sign in to comment.