Phaser.FlexGrid = function (manager, width, height){ this.game = manager.game; this.manager = manager; this.width = width; this.height = height; this.boundsCustom = new Phaser.Rectangle(0, 0, width, height); this.boundsFluid = new Phaser.Rectangle(0, 0, width, height); this.boundsFull = new Phaser.Rectangle(0, 0, width, height); this.boundsNone = new Phaser.Rectangle(0, 0, width, height); this.positionCustom = new Phaser.Point(0, 0); this.positionFluid = new Phaser.Point(0, 0); this.positionFull = new Phaser.Point(0, 0); this.positionNone = new Phaser.Point(0, 0); this.scaleCustom = new Phaser.Point(1, 1); this.scaleFluid = new Phaser.Point(1, 1); this.scaleFluidInversed = new Phaser.Point(1, 1); this.scaleFull = new Phaser.Point(1, 1); this.scaleNone = new Phaser.Point(1, 1); this.customWidth = 0; this.customHeight = 0; this.customOffsetX = 0; this.customOffsetY = 0; this.ratioH = width / height; this.ratioV = height / width; this.multiplier = 0; this.layers = [] ; } ; Phaser.FlexGrid.prototype = { setSize: function (width, height){ this.width = width; this.height = height; this.ratioH = width / height; this.ratioV = height / width; this.scaleNone = new Phaser.Point(1, 1); this.boundsNone.width = this.width; this.boundsNone.height = this.height; _AN_Call_refresh('refresh', this); } , createCustomLayer: function (width, height, children, addToWorld){ if (addToWorld === undefined) { addToWorld = true ; } this.customWidth = width; this.customHeight = height; this.boundsCustom.width = width; this.boundsCustom.height = height; var layer = new Phaser.FlexLayer(this, this.positionCustom, this.boundsCustom, this.scaleCustom); if (addToWorld) { this.game.world.add(layer); } this.layers.push(layer); if (typeof children !== 'undefined' && typeof children !== null ) { layer.addMultiple(children); } return layer; } , createFluidLayer: function (children, addToWorld){ if (addToWorld === undefined) { addToWorld = true ; } var layer = new Phaser.FlexLayer(this, this.positionFluid, this.boundsFluid, this.scaleFluid); if (addToWorld) { this.game.world.add(layer); } this.layers.push(layer); if (typeof children !== 'undefined' && typeof children !== null ) { layer.addMultiple(children); } return layer; } , createFullLayer: function (children){ var layer = new Phaser.FlexLayer(this, this.positionFull, this.boundsFull, this.scaleFluid); this.game.world.add(layer); this.layers.push(layer); if (typeof children !== 'undefined') { layer.addMultiple(children); } return layer; } , createFixedLayer: function (children){ var layer = new Phaser.FlexLayer(this, this.positionNone, this.boundsNone, this.scaleNone); this.game.world.add(layer); this.layers.push(layer); if (typeof children !== 'undefined') { layer.addMultiple(children); } return layer; } , reset: function (){ var i = _AN_Read_length('length', this.layers); while (i-- ){ if (!this.layers[i].persist) { this.layers[i].position = null ; this.layers[i].scale = null ; this.layers.slice(i, 1); } } } , onResize: function (width, height){ this.ratioH = width / height; this.ratioV = height / width; _AN_Call_refresh('refresh', this, width, height); } , refresh: function (){ this.multiplier = Math.min((this.manager.height / this.height), (this.manager.width / this.width)); this.boundsFluid.width = Math.round(this.width * this.multiplier); this.boundsFluid.height = Math.round(this.height * this.multiplier); this.scaleFluid.set(this.boundsFluid.width / this.width, this.boundsFluid.height / this.height); this.scaleFluidInversed.set(this.width / this.boundsFluid.width, this.height / this.boundsFluid.height); this.scaleFull.set(this.boundsFull.width / this.width, this.boundsFull.height / this.height); this.boundsFull.width = Math.round(this.manager.width * this.scaleFluidInversed.x); this.boundsFull.height = Math.round(this.manager.height * this.scaleFluidInversed.y); this.boundsFluid.centerOn(this.manager.bounds.centerX, this.manager.bounds.centerY); this.boundsNone.centerOn(this.manager.bounds.centerX, this.manager.bounds.centerY); this.positionFluid.set(this.boundsFluid.x, this.boundsFluid.y); this.positionNone.set(this.boundsNone.x, this.boundsNone.y); } , fitSprite: function (sprite){ this.manager.scaleSprite(sprite); sprite.x = this.manager.bounds.centerX; sprite.y = this.manager.bounds.centerY; } , debug: function (){ this.game.debug.text(this.boundsFluid.width + ' x ' + this.boundsFluid.height, this.boundsFluid.x + 4, this.boundsFluid.y + 16); this.game.debug.geom(this.boundsFluid, 'rgba(255,0,0,0.9', false ); } } ; Phaser.FlexGrid.prototype.constructor = Phaser.FlexGrid;