Skip to content

Commit

Permalink
Merge pull request #955 from gopeter/develop
Browse files Browse the repository at this point in the history
Fixed _clamp function for scaled viewports
  • Loading branch information
starwed committed Sep 19, 2015
2 parents fe26b9d + 9fee3cb commit 120d227
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/graphics/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,23 +485,23 @@ 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;
}
} else {
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;
}
Expand Down

0 comments on commit 120d227

Please sign in to comment.