var EHDI = EHDI || Object.create(null); EHDI.GAME = EHDI.GAME || Object.create(null); EHDI.GAME.components = EHDI.GAME.components || Object.create(null); EHDI.GAME.components.Background = function(bgSprite) { var texture; if(bgSprite == undefined) texture = EHDI.GAME.SpriteManager.getRandomSprite(EHDI.GAME.SpriteManager.bgSpriteList); else texture = EHDI.GAME.SpriteManager.getSpriteByName(EHDI.GAME.SpriteManager.bgSpriteList, bgSprite); EHDI.aka.Sprite.call(this, texture); this.position.x = 0; this.position.y = 0; this.scaleToFit(); } EHDI.GAME.components.Background.prototype = Object.create(EHDI.aka.Sprite.prototype); EHDI.GAME.components.Background.prototype.scaleToFit = function() { this.texture.baseTexture.scaleMode = PIXI.SCALE_MODES.NEAREST; this.scale.x = (EHDI.GAME.sceneManager.getStageWidth()/this.width); this.scale.y = EHDI.GAME.sceneManager.getStageHeight()/this.height; } EHDI.GAME.components.Background.prototype.switch = function() { this.scale.x = 1; this.scale.y = 1; this.texture = EHDI.GAME.SpriteManager.getRandomSprite(EHDI.GAME.SpriteManager.bgSpriteList); this.scaleToFit(); }