diff --git a/src/graphics/viewport.js b/src/graphics/viewport.js index 2e6534a2..f0582cb5 100644 --- a/src/graphics/viewport.js +++ b/src/graphics/viewport.js @@ -485,14 +485,14 @@ Crafty.extend({ // clamps the viewport to the viewable area // under no circumstances should the viewport see something outside the boundary of the 'world' if (!this.clampToEntities) return; - var bound = this.bounds || Crafty.map.boundaries(); + var bound = Crafty.clone(this.bounds) || Crafty.map.boundaries(); bound.max.x *= this._scale; bound.min.x *= this._scale; bound.max.y *= this._scale; bound.min.y *= this._scale; if (bound.max.x - bound.min.x > Crafty.viewport.width) { - if (Crafty.viewport.x < -bound.max.x + Crafty.viewport.width) { - Crafty.viewport.x = -bound.max.x + Crafty.viewport.width; + if (Crafty.viewport.x < (-bound.max.x + Crafty.viewport.width) / this._scale) { + Crafty.viewport.x = (-bound.max.x + Crafty.viewport.width) / this._scale; } else if (Crafty.viewport.x > -bound.min.x) { Crafty.viewport.x = -bound.min.x; } @@ -500,8 +500,8 @@ Crafty.extend({ Crafty.viewport.x = -1 * (bound.min.x + (bound.max.x - bound.min.x) / 2 - Crafty.viewport.width / 2); } if (bound.max.y - bound.min.y > Crafty.viewport.height) { - if (Crafty.viewport.y < -bound.max.y + Crafty.viewport.height) { - Crafty.viewport.y = -bound.max.y + Crafty.viewport.height; + if (Crafty.viewport.y < (-bound.max.y + Crafty.viewport.height) / this._scale) { + Crafty.viewport.y = (-bound.max.y + Crafty.viewport.height) / this._scale; } else if (Crafty.viewport.y > -bound.min.y) { Crafty.viewport.y = -bound.min.y; }