Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created November 17, 2015 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/4dafb4158f727ce34d53 to your computer and use it in GitHub Desktop.
Save drhayes/4dafb4158f727ce34d53 to your computer and use it in GitHub Desktop.
Phaser.Camera.js updateTargetTrackSlow
updateTargetTrackSlow() {
// We always have a deadzone. If we don't, that means we haven't set the target yet so
// there's no sense in doing anything in this method yet.
if (!this.deadzone) {
return;
}
this._targetPosition.copyFrom(this.target);
if (this.target.parent) {
this._targetPosition.multiply(this.target.parent.worldTransform.a, this.target.parent.worldTransform.d);
}
let edge = this._targetPosition.x - this.view.x;
let deltaX = 0;
let deltaY = 0;
if (edge < this.deadzone.left) {
deltaX = this._targetPosition.x - this.view.x - this.deadzone.left;
} else if (edge > this.deadzone.right) {
deltaX = this._targetPosition.x - this.view.x - this.deadzone.right;
}
edge = this._targetPosition.y - this.view.y;
if (edge < this.deadzone.top) {
deltaY = this._targetPosition.y - this.view.y - this.deadzone.top;
} else if (edge > this.deadzone.bottom) {
deltaY = this._targetPosition.y - this.view.y - this.deadzone.bottom;
}
if (this.target.standing) {
deltaY = this._targetPosition.y - this.view.y - this.deadzone.bottom;
}
this.view.x += Math.ceil(deltaX * 0.1);
this.view.y += Math.ceil(deltaY * 0.05);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment