Permalink
Browse files

Handle case when boundaries is smaller than viewport.

  • Loading branch information...
1 parent b5b7334 commit 923e4a03162633b98ecd50c43e4e1467f3809c86 @mpetrovic mpetrovic committed Jan 10, 2012
Showing with 22 additions and 12 deletions.
  1. +22 −12 src/extensions.js
View
@@ -608,22 +608,32 @@ Crafty.extend({
// clamps the viewport to the viewable area
// under no circumstances should the viewport see something outside the boundary of the 'world'
var bound = Crafty.map.boundaries();
- bound.max.x -= Crafty.viewport.width;
- bound.max.y -= Crafty.viewport.height;
+ if (bound.max.x - bound.min.x > Crafty.viewport.width) {
+ bound.max.x -= Crafty.viewport.width;
- if (Crafty.viewport.x < -bound.max.x) {
- Crafty.viewport.x = -bound.max.x;
+ if (Crafty.viewport.x < -bound.max.x) {
+ Crafty.viewport.x = -bound.max.x;
+ }
+ else if (Crafty.viewport.x > -bound.min.x) {
+ Crafty.viewport.x = -bound.min.x;
+ }
}
- 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 (Crafty.viewport.y < -bound.max.y) {
- Crafty.viewport.y = -bound.max.y;
+ if (bound.max.y - bound.min.y > Crafty.viewport.height) {
+ bound.max.y -= Crafty.viewport.height;
+
+ if (Crafty.viewport.y < -bound.max.y) {
+ Crafty.viewport.y = -bound.max.y;
+ }
+ else if (Crafty.viewport.y > -bound.min.y) {
+ Crafty.viewport.y = -bound.min.y;
+ }
+ }
+ else {
+ Crafty.viewport.y = -1*(bound.min.y + (bound.max.y - bound.min.y)/2 - Crafty.viewport.height/2);
}
- else if (Crafty.viewport.y > -bound.min.y) {
- Crafty.viewport.y = -bound.min.y;
- }
},
init: function(w,h) {

0 comments on commit 923e4a0

Please sign in to comment.