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); } ; Phaser.Camera.FOLLOW_LOCKON = 0; Phaser.Camera.FOLLOW_PLATFORMER = 1; Phaser.Camera.FOLLOW_TOPDOWN = 2; Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3; Phaser.Camera.prototype = { game: null , world: null , id: 0, view: null , deadzone: null , visible: true , target: null , 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.Types.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.Types.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.Types.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.Types.CAMERA_FOLLOW_LOCKON: default : { this.deadzone = null ; break ; } } } , focusOnXY: function (x, y){ x += (x > 0)? 1e-07: -1e-07; y += (y > 0)? 1e-07: -1e-07; this.view.x = Math.round(x - this.view.halfWidth); this.view.y = Math.round(y - this.view.halfHeight); } , update: function (){ if (_AN_Read_target("target", this) !== null ) { if (this.deadzone == null ) { this.focusOnXY(_AN_Read_target("target", this).x, _AN_Read_target("target", this).y); } else { var edge; var targetX = _AN_Read_target("target", this).x + ((_AN_Read_target("target", this).x > 0)? 1e-07: -1e-07); var targetY = _AN_Read_target("target", this).y + ((_AN_Read_target("target", this).y > 0)? 1e-07: -1e-07); edge = targetX - this.deadzone.x; if (this.view.x > edge) { this.view.x = edge; } edge = targetX + _AN_Read_target("target", this).width - this.deadzone.x - this.deadzone.width; if (this.view.x < edge) { this.view.x = edge; } edge = targetY - this.deadzone.y; if (this.view.y > edge) { this.view.y = edge; } edge = targetY + _AN_Read_target("target", this).height - this.deadzone.y - this.deadzone.height; if (this.view.y < edge) { this.view.y = edge; } } } if (this.view.x < this.world.bounds.left) { this.view.x = this.world.bounds.left; } if (this.view.x > this.world.bounds.right - this.width) { this.view.x = (this.world.bounds.right - this.width) + 1; } if (this.view.y < this.world.bounds.top) { this.view.y = this.world.bounds.top; } if (this.view.y > this.world.bounds.bottom - this.height) { this.view.y = (this.world.bounds.bottom - this.height) + 1; } this.view.floor(); } , setPosition: function (x, y){ this.view.x = x; this.view.y = y; } , setSize: function (width, height){ this.view.width = width; this.view.height = height; } } ; Object.defineProperty(Phaser.Camera.prototype, "x", { get: function (){ return this.view.x; } , set: function (value){ this.view.x = value; } , enumerable: true , configurable: true } ); Object.defineProperty(Phaser.Camera.prototype, "y", { get: function (){ return this.view.y; } , set: function (value){ this.view.y = value; } , enumerable: true , configurable: true } ); Object.defineProperty(Phaser.Camera.prototype, "width", { get: function (){ return this.view.width; } , set: function (value){ this.view.width = value; } , enumerable: true , configurable: true } ); Object.defineProperty(Phaser.Camera.prototype, "height", { get: function (){ return this.view.height; } , set: function (value){ this.view.height = value; } , enumerable: true , configurable: true } );