Phaser.Image = function (game, x, y, key, frame){ x = x || 0; y = y || 0; key = key || null ; frame = frame || null ; this.game = game; this.exists = true ; this.name = ''; this.type = Phaser.IMAGE; this.z = 0; this.events = new Phaser.Events(this); this.key = key; this._frame = 0; this._frameName = ''; PIXI.Sprite.call(this, PIXI.TextureCache.__default); this.loadTexture(key, frame); this.position.set(x, y); this.world = new Phaser.Point(x, y); this.autoCull = false ; this.input = null ; this.cameraOffset = new Phaser.Point(); this._cache = [0, 0, 0, 0, 1, 0, 1, 0] ; } ; Phaser.Image.prototype = Object.create(PIXI.Sprite.prototype); Phaser.Image.prototype.constructor = Phaser.Image; Phaser.Image.prototype.preUpdate = function (){ this._cache[0] = this.world.x; this._cache[1] = this.world.y; this._cache[2] = this.rotation; if (!this.exists || !this.parent.exists) { this._cache[3] = -1; return false ; } if (this.autoCull) { this.renderable = this.game.world.camera.screenView.intersects(this.getBounds()); } this.world.setTo(this.game.camera.x + this.worldTransform[2], this.game.camera.y + this.worldTransform[5]); if (this.visible) { this._cache[3] = this.game.stage.currentRenderOrderID++ ; } for (var i = 0, len = _AN_Read_length('length', this.children); i < len; i++ ){ this.children[i].preUpdate(); } return true ; } ; Phaser.Image.prototype.update = function (){ } ; Phaser.Image.prototype.postUpdate = function (){ if (this.key instanceof Phaser.BitmapData && this.key._dirty) { this.key.render(); } if (this._cache[7] === 1) { this.position.x = (this.game.camera.view.x + this.cameraOffset.x) / this.game.camera.scale.x; this.position.y = (this.game.camera.view.y + this.cameraOffset.y) / this.game.camera.scale.y; } for (var i = 0, len = _AN_Read_length('length', this.children); i < len; i++ ){ this.children[i].postUpdate(); } } ; Phaser.Image.prototype.loadTexture = function (key, frame){ frame = frame || 0; if (key instanceof Phaser.RenderTexture) { this.key = key.key; this.setTexture(key); return ; } else if (key instanceof Phaser.BitmapData) { this.key = key.key; this.setTexture(key.texture); return ; } else if (key instanceof PIXI.Texture) { this.key = key; this.setTexture(key); return ; } else { if (key === null || typeof key === 'undefined') { this.key = '__default'; this.setTexture(PIXI.TextureCache[this.key]); return ; } else if (typeof key === 'string' && !this.game.cache.checkImageKey(key)) { this.key = '__missing'; this.setTexture(PIXI.TextureCache[this.key]); return ; } if (this.game.cache.isSpriteSheet(key)) { this.key = key; var frameData = this.game.cache.getFrameData(key); if (typeof frame === 'string') { this._frame = 0; this._frameName = frame; this.setTexture(PIXI.TextureCache[frameData.getFrameByName(frame).uuid]); return ; } else { this._frame = frame; this._frameName = ''; this.setTexture(PIXI.TextureCache[frameData.getFrame(frame).uuid]); return ; } } else { this.key = key; this.setTexture(PIXI.TextureCache[key]); return ; } } } ; Phaser.Image.prototype.crop = function (rect){ if (typeof rect === 'undefined' || rect === null ) { if (this.texture.hasOwnProperty('sourceWidth')) { this.texture.setFrame(new Phaser.Rectangle(0, 0, this.texture.sourceWidth, this.texture.sourceHeight)); } } else { if (this.texture instanceof PIXI.Texture) { var local = { } ; Phaser.Utils.extend(true , local, this.texture); local.sourceWidth = local.width; local.sourceHeight = local.height; local.frame = rect; local.width = rect.width; local.height = rect.height; this.texture = local; this.texture.updateFrame = true ; PIXI.Texture.frameUpdates.push(this.texture); } else { this.texture.setFrame(rect); } } } ; Phaser.Image.prototype.revive = function (){ this.alive = true ; this.exists = true ; this.visible = true ; if (this.events) { this.events.onRevived.dispatch(this); } return this; } ; Phaser.Image.prototype.kill = function (){ this.alive = false ; this.exists = false ; this.visible = false ; if (this.events) { this.events.onKilled.dispatch(this); } return this; } ; Phaser.Image.prototype.destroy = function (destroyChildren){ if (this.game === null ) { return ; } if (typeof destroyChildren === 'undefined') { destroyChildren = true ; } if (this.parent) { if (this.parent instanceof Phaser.Group) { this.parent.remove(this); } else { this.parent.removeChild(this); } } if (this.events) { this.events.destroy(); } if (this.input) { this.input.destroy(); } var i = _AN_Read_length('length', this.children); if (destroyChildren) { while (i-- ){ this.children[i].destroy(destroyChildren); } } else { while (i-- ){ this.removeChild(this.children[i]); } } this.alive = false ; this.exists = false ; this.visible = false ; this.filters = null ; this.mask = null ; this.game = null ; } ; Phaser.Image.prototype.reset = function (x, y){ this.world.setTo(x, y); this.position.x = x; this.position.y = y; this.alive = true ; this.exists = true ; this.visible = true ; this.renderable = true ; return this; } ; Phaser.Image.prototype.bringToTop = function (){ if (this.parent) { this.parent.bringToTop(this); } return this; } ; Object.defineProperty(Phaser.Image.prototype, "angle", { get: function (){ return Phaser.Math.wrapAngle(Phaser.Math.radToDeg(this.rotation)); } , set: function (value){ this.rotation = Phaser.Math.degToRad(Phaser.Math.wrapAngle(value)); } } ); Object.defineProperty(Phaser.Image.prototype, "deltaX", { get: function (){ return this.world.x - this._cache[0]; } } ); Object.defineProperty(Phaser.Image.prototype, "deltaY", { get: function (){ return this.world.y - this._cache[1]; } } ); Object.defineProperty(Phaser.Image.prototype, "deltaZ", { get: function (){ return this.rotation - this._cache[2]; } } ); Object.defineProperty(Phaser.Image.prototype, "inWorld", { get: function (){ return this.game.world.bounds.intersects(this.getBounds()); } } ); Object.defineProperty(Phaser.Image.prototype, "inCamera", { get: function (){ return this.game.world.camera.screenView.intersects(this.getBounds()); } } ); Object.defineProperty(Phaser.Image.prototype, "frame", { get: function (){ return this._frame; } , set: function (value){ if (value !== this.frame && this.game.cache.isSpriteSheet(this.key)) { var frameData = this.game.cache.getFrameData(this.key); if (frameData && value < frameData.total && frameData.getFrame(value)) { this.setTexture(PIXI.TextureCache[frameData.getFrame(value).uuid]); this._frame = value; } } } } ); Object.defineProperty(Phaser.Image.prototype, "frameName", { get: function (){ return this._frameName; } , set: function (value){ if (value !== this.frameName && this.game.cache.isSpriteSheet(this.key)) { var frameData = this.game.cache.getFrameData(this.key); if (frameData && frameData.getFrameByName(value)) { this.setTexture(PIXI.TextureCache[frameData.getFrameByName(value).uuid]); this._frameName = value; } } } } ); Object.defineProperty(Phaser.Image.prototype, "renderOrderID", { get: function (){ return this._cache[3]; } } ); Object.defineProperty(Phaser.Image.prototype, "inputEnabled", { get: function (){ return (this.input && this.input.enabled); } , set: function (value){ if (value) { if (this.input === null ) { this.input = new Phaser.InputHandler(this); this.input.start(); } } else { if (this.input && this.input.enabled) { this.input.stop(); } } } } ); Object.defineProperty(Phaser.Image.prototype, "fixedToCamera", { get: function (){ return !!this._cache[7]; } , set: function (value){ if (value) { this._cache[7] = 1; this.cameraOffset.set(this.x, this.y); } else { this._cache[7] = 0; } } } ); Object.defineProperty(Phaser.Image.prototype, "smoothed", { get: function (){ return !this.texture.baseTexture.scaleMode; } , set: function (value){ if (value) { if (this.texture) { this.texture.baseTexture.scaleMode = 0; } } else { if (this.texture) { this.texture.baseTexture.scaleMode = 1; } } } } );