Phaser.TileSprite = function (game, x, y, width, height, key, frame){ x = x || 0; y = y || 0; width = width || 256; height = height || 256; key = key || null ; frame = frame || null ; this.game = game; this.name = ''; this.type = Phaser.TILESPRITE; this.z = 0; this.events = new Phaser.Events(this); this.animations = new Phaser.AnimationManager(this); this.key = key; this._frame = 0; this._frameName = ''; this._scroll = new Phaser.Point(); PIXI.TilingSprite.call(this, PIXI.TextureCache.__default, width, height); this.position.set(x, y); this.input = null ; this.world = new Phaser.Point(x, y); this.autoCull = false ; this.checkWorldBounds = false ; this.cameraOffset = new Phaser.Point(); this.body = null ; this.alive = true ; this._cache = [0, 0, 0, 0, 1, 0, 1, 0, 0] ; this.loadTexture(key, frame); } ; Phaser.TileSprite.prototype = Object.create(PIXI.TilingSprite.prototype); Phaser.TileSprite.prototype.constructor = Phaser.TileSprite; Phaser.TileSprite.prototype.preUpdate = function (){ if (this._cache[4] === 1 && this.exists) { this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y); this.worldTransform.tx = this.world.x; this.worldTransform.ty = this.world.y; this._cache[0] = this.world.x; this._cache[1] = this.world.y; this._cache[2] = this.rotation; if (this.body) { this.body.preUpdate(); } this._cache[4] = 0; return false ; } 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.checkWorldBounds) { this._bounds.copyFrom(this.getBounds()); } if (this.autoCull) { this.renderable = this.game.world.camera.screenView.intersects(this._bounds); } if (this.checkWorldBounds) { if (this._cache[5] === 1 && this.game.world.bounds.intersects(this._bounds)) { this._cache[5] = 0; this.events.onEnterBounds.dispatch(this); } else if (this._cache[5] === 0 && !this.game.world.bounds.intersects(this._bounds)) { this._cache[5] = 1; this.events.onOutOfBounds.dispatch(this); } } this.world.setTo(this.game.camera.x + this.worldTransform.tx, this.game.camera.y + this.worldTransform.ty); if (this.visible) { this._cache[3] = this.game.stage.currentRenderOrderID++ ; } this.animations.update(); if (this._scroll.x !== 0) { this.tilePosition.x += this._scroll.x * this.game.time.physicsElapsed; } if (this._scroll.y !== 0) { this.tilePosition.y += this._scroll.y * this.game.time.physicsElapsed; } if (this.body) { this.body.preUpdate(); } for (var i = 0, len = _AN_Read_length('length', this.children); i < len; i++ ){ this.children[i].preUpdate(); } return true ; } ; Phaser.TileSprite.prototype.update = function (){ } ; Phaser.TileSprite.prototype.postUpdate = function (){ if (this.exists && this.body) { this.body.postUpdate(); } if (this._cache[7] === 1) { this.position.x = this.game.camera.view.x + this.cameraOffset.x; this.position.y = this.game.camera.view.y + this.cameraOffset.y; } for (var i = 0, len = _AN_Read_length('length', this.children); i < len; i++ ){ this.children[i].postUpdate(); } } ; Phaser.TileSprite.prototype.autoScroll = function (x, y){ this._scroll.set(x, y); } ; Phaser.TileSprite.prototype.stopScroll = function (){ this._scroll.set(0, 0); } ; Phaser.TileSprite.prototype.loadTexture = function (key, frame){ frame = frame || 0; this.key = key; if (key instanceof Phaser.RenderTexture) { this.key = key.key; this.setTexture(key); } else if (key instanceof Phaser.BitmapData) { this.setTexture(key.texture); } else if (key instanceof PIXI.Texture) { this.setTexture(key); } else { if (key === null || typeof key === 'undefined') { this.key = '__default'; this.setTexture(PIXI.TextureCache[this.key]); } else if (typeof key === 'string' && !this.game.cache.checkImageKey(key)) { console.warn("Texture with key '" + key + "' not found."); this.key = '__missing'; this.setTexture(PIXI.TextureCache[this.key]); } else { this.setTexture(new PIXI.Texture(PIXI.BaseTextureCache[key])); this.animations.loadFrameData(this.game.cache.getFrameData(key), frame); } } } ; Phaser.TileSprite.prototype.setFrame = function (frame){ this.texture.frame.x = frame.x; this.texture.frame.y = frame.y; this.texture.frame.width = frame.width; this.texture.frame.height = frame.height; this.texture.crop.x = frame.x; this.texture.crop.y = frame.y; this.texture.crop.width = frame.width; this.texture.crop.height = frame.height; if (frame.trimmed) { if (this.texture.trim) { this.texture.trim.x = frame.spriteSourceSizeX; this.texture.trim.y = frame.spriteSourceSizeY; this.texture.trim.width = frame.sourceSizeW; this.texture.trim.height = frame.sourceSizeH; } else { this.texture.trim = { x: frame.spriteSourceSizeX, y: frame.spriteSourceSizeY, width: frame.sourceSizeW, height: frame.sourceSizeH} ; } this.texture.width = frame.sourceSizeW; this.texture.height = frame.sourceSizeH; this.texture.frame.width = frame.sourceSizeW; this.texture.frame.height = frame.sourceSizeH; } else if (!frame.trimmed && this.texture.trim) { this.texture.trim = null ; } if (this.game.renderType === Phaser.WEBGL) { PIXI.WebGLRenderer.updateTextureFrame(this.texture); } } ; Phaser.TileSprite.prototype.destroy = function (destroyChildren){ if (this.game === null || this.destroyPhase) { return ; } if (typeof destroyChildren === 'undefined') { destroyChildren = true ; } this._cache[8] = 1; if (this.events) { this.events.onDestroy.dispatch(this); } if (this.filters) { this.filters = null ; } if (this.parent) { if (this.parent instanceof Phaser.Group) { this.parent.remove(this); } else { this.parent.removeChild(this); } } this.animations.destroy(); this.events.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.exists = false ; this.visible = false ; this.alive = false ; this.filters = null ; this.mask = null ; this.game = null ; this._cache[8] = 0; } ; Phaser.TileSprite.prototype.play = function (name, frameRate, loop, killOnComplete){ return this.animations.play(name, frameRate, loop, killOnComplete); } ; Phaser.TileSprite.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 ; this._outOfBoundsFired = false ; this.tilePosition.x = 0; this.tilePosition.y = 0; if (this.body) { this.body.reset(x, y, false , false ); } this._cache[4] = 1; return this; } ; Object.defineProperty(Phaser.TileSprite.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.TileSprite.prototype, "frame", { get: function (){ return this.animations.frame; } , set: function (value){ if (value !== this.animations.frame) { this.animations.frame = value; } } } ); Object.defineProperty(Phaser.TileSprite.prototype, "frameName", { get: function (){ return this.animations.frameName; } , set: function (value){ if (value !== this.animations.frameName) { this.animations.frameName = value; } } } ); Object.defineProperty(Phaser.TileSprite.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.TileSprite.prototype, "exists", { get: function (){ return !!this._cache[6]; } , set: function (value){ if (value) { this._cache[6] = 1; if (this.body && this.body.type === Phaser.Physics.P2JS) { this.body.addToWorld(); } this.visible = true ; } else { this._cache[6] = 0; if (this.body && this.body.type === Phaser.Physics.P2JS) { this.body.safeRemove = true ; } this.visible = false ; } } } ); Object.defineProperty(Phaser.TileSprite.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.start(); } } else { if (this.input && this.input.enabled) { this.input.stop(); } } } } ); Object.defineProperty(Phaser.TileSprite.prototype, "x", { get: function (){ return this.position.x; } , set: function (value){ this.position.x = value; if (this.body && this.body.type === Phaser.Physics.ARCADE && this.body.phase === 2) { this.body._reset = 1; } } } ); Object.defineProperty(Phaser.TileSprite.prototype, "y", { get: function (){ return this.position.y; } , set: function (value){ this.position.y = value; if (this.body && this.body.type === Phaser.Physics.ARCADE && this.body.phase === 2) { this.body._reset = 1; } } } ); Object.defineProperty(Phaser.TileSprite.prototype, "destroyPhase", { get: function (){ return !!this._cache[8]; } } );