Created
November 17, 2015 03:00
-
-
Save drhayes/4dafb4158f727ce34d53 to your computer and use it in GitHub Desktop.
Phaser.Camera.js updateTargetTrackSlow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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