From b15fb1de3b445f80ef76a921392a4559baf04f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20G=C3=B6bel?= Date: Mon, 17 Aug 2015 11:20:17 +0200 Subject: [PATCH 1/2] clone bounds to prevent overriding original values --- src/graphics/viewport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/viewport.js b/src/graphics/viewport.js index 2e6534a2..e4d846c0 100644 --- a/src/graphics/viewport.js +++ b/src/graphics/viewport.js @@ -485,7 +485,7 @@ 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; From 9fee3cb71dd44cb66a7191f01c93273f72044425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20G=C3=B6bel?= Date: Mon, 17 Aug 2015 11:22:17 +0200 Subject: [PATCH 2/2] consider scale when calculating viewport --- src/graphics/viewport.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/graphics/viewport.js b/src/graphics/viewport.js index e4d846c0..f0582cb5 100644 --- a/src/graphics/viewport.js +++ b/src/graphics/viewport.js @@ -491,8 +491,8 @@ Crafty.extend({ 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; }