Skip to content

Instantly share code, notes, and snippets.

@beckyconning
Created October 13, 2012 20:20
Show Gist options
  • Save beckyconning/3885998 to your computer and use it in GitHub Desktop.
Save beckyconning/3885998 to your computer and use it in GitHub Desktop.
Crafty viewport relative position component
Crafty.c("ViewportRelative", {
_viewportPreviousX: 0,
_viewportPreviousY: 0,
_viewportStartX: 0,
_viewportStartY: 0,
init: function() {
this.bind("EnterFrame", this._frame);
},
_frame: function() {
if(this._viewportPreviousX != Crafty.viewport._x) {
this._viewportStartX = Crafty.viewport._x;
this.x += this._viewportPreviousX
this.x -= Crafty.viewport._x;
this._viewportPreviousX = this._viewportStartX;
}
if(this._viewportPreviousY != Crafty.viewport._y) {
this._viewportStartY = Crafty.viewport._y;
this.x += this._viewportPreviousY
this.x -= Crafty.viewport._y;
this._viewportPreviousX = this._viewportStartX;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment