Phaser.Camera = function (game, id, x, y, width, height){ this.game = game; this.world = game.world; this.id = 0; this.view = new Phaser.Rectangle(x, y, width, height); this.screenView = new Phaser.Rectangle(x, y, width, height); this.bounds = new Phaser.Rectangle(x, y, width, height); this.deadzone = null ; this.visible = true ; this.atLimit = { x: false , y: false } ; _AN_Write_target('target', this, false , null ); this._edge = 0; this.displayObject = null ; } ; Phaser.Camera.FOLLOW_LOCKON = 0; Phaser.Camera.FOLLOW_PLATFORMER = 1; Phaser.Camera.FOLLOW_TOPDOWN = 2; Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3; Phaser.Camera.prototype = { follow: function (target, style){ if (typeof style === "undefined") { style = Phaser.Camera.FOLLOW_LOCKON; } _AN_Write_target("target", this, false , target); var helper; switch (style){ case Phaser.Camera.FOLLOW_PLATFORMER: var w = this.width / 8; var h = this.height / 3; this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h); break ; case Phaser.Camera.FOLLOW_TOPDOWN: helper = Math.max(this.width, this.height) / 4; this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper); break ; case Phaser.Camera.FOLLOW_TOPDOWN_TIGHT: helper = Math.max(this.width, this.height) / 8; this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper); break ; case Phaser.Camera.FOLLOW_LOCKON: this.deadzone = null ; break ; default : { this.deadzone = null ; break ; } } } , focusOn: function (displayObject){ this.setPosition(Math.round(displayObject.x - this.view.halfWidth), Math.round(displayObject.y - this.view.halfHeight)); } , focusOnXY: function (x, y){ this.setPosition(Math.round(x - this.view.halfWidth), Math.round(y - this.view.halfHeight)); } , update: function (){ if (this.target) { this.updateTarget(); } if (this.bounds) { this.checkBounds(); } this.displayObject.position.x = - this.view.x; this.displayObject.position.y = - this.view.y; } , updateTarget: function (){ if (this.deadzone) { this._edge = _AN_Read_target("target", this).x - this.deadzone.x; if (this.view.x > this._edge) { this.view.x = this._edge; } this._edge = _AN_Read_target("target", this).x + _AN_Read_target("target", this).width - this.deadzone.x - this.deadzone.width; if (this.view.x < this._edge) { this.view.x = this._edge; } this._edge = _AN_Read_target("target", this).y - this.deadzone.y; if (this.view.y > this._edge) { this.view.y = this._edge; } this._edge = _AN_Read_target("target", this).y + _AN_Read_target("target", this).height - this.deadzone.y - this.deadzone.height; if (this.view.y < this._edge) { this.view.y = this._edge; } } else { this.focusOnXY(_AN_Read_target("target", this).x, _AN_Read_target("target", this).y); } } , setBoundsToWorld: function (){ this.bounds.setTo(this.game.world.bounds.x, this.game.world.bounds.y, this.game.world.bounds.width, this.game.world.bounds.height); } , checkBounds: function (){ this.atLimit.x = false ; this.atLimit.y = false ; if (this.view.x < this.bounds.x) { this.atLimit.x = true ; this.view.x = this.bounds.x; } if (this.view.right > this.bounds.right) { this.atLimit.x = true ; this.view.x = this.bounds.right - this.width; } if (this.view.y < this.bounds.top) { this.atLimit.y = true ; this.view.y = this.bounds.top; } if (this.view.bottom > this.bounds.bottom) { this.atLimit.y = true ; this.view.y = this.bounds.bottom - this.height; } this.view.floor(); } , setPosition: function (x, y){ this.view.x = x; this.view.y = y; if (this.bounds) { this.checkBounds(); } } , setSize: function (width, height){ this.view.width = width; this.view.height = height; } , reset: function (){ _AN_Write_target("target", this, false , null ); this.view.x = 0; this.view.y = 0; } } ; Phaser.Camera.prototype.constructor = Phaser.Camera; Object.defineProperty(Phaser.Camera.prototype, "x", { get: function (){ return this.view.x; } , set: function (value){ this.view.x = value; if (this.bounds) { this.checkBounds(); } } } ); Object.defineProperty(Phaser.Camera.prototype, "y", { get: function (){ return this.view.y; } , set: function (value){ this.view.y = value; if (this.bounds) { this.checkBounds(); } } } ); Object.defineProperty(Phaser.Camera.prototype, "width", { get: function (){ return this.view.width; } , set: function (value){ this.view.width = value; } } ); Object.defineProperty(Phaser.Camera.prototype, "height", { get: function (){ return this.view.height; } , set: function (value){ this.view.height = value; } } );