Skip to content

Commit

Permalink
Merge pull request #522 from ericathegreat/centerOn-scrolling-bugfix
Browse files Browse the repository at this point in the history
Fixing a bug in centerOn for non-zero origins
  • Loading branch information
starwed committed Aug 8, 2013
2 parents 425b11a + fa4ad57 commit b4cd71d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ Crafty.extend({
* Centers the viewport on the given entity
*/
centerOn: function (targ, time) {
var x = targ.x,
y = targ.y,
var x = targ.x + Crafty.viewport.x,
y = targ.y + Crafty.viewport.y,
mid_x = targ.w / 2,
mid_y = targ.h / 2,
cent_x = Crafty.viewport.width / 2,
Expand Down
9 changes: 9 additions & 0 deletions tests/stage.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
Crafty.timer.simulateFrames(10);
equal(Crafty.viewport._x, -e.w / 2 + Crafty.viewport.width / 2, "Entity still centered 10 frames later");


var e2 = Crafty.e("2D, DOM").attr({ x: 450, y: 450, w: 20, h: 20 });
Crafty.viewport.scroll('x', 1500);
Crafty.viewport.scroll('y', 300);
Crafty.viewport.centerOn(e2, 1);
Crafty.timer.simulateFrames(1);
equal(Crafty.viewport._x, -(e2.x + e2.w/2 - Crafty.viewport.width / 2), "Entity centered from non-zero origin");
equal(Crafty.viewport._y, -(e2.y + e2.h/2 - Crafty.viewport.height / 2), "Entity centered from non-zero origin");

Crafty.viewport.scroll('x', 0);
Crafty.viewport.scroll('y', 0);
});
Expand Down

0 comments on commit b4cd71d

Please sign in to comment.