@@ -27,34 +27,31 @@ Phaser.FlexGrid = function (manager, width, height) {
2727 this . width = width ;
2828 this . height = height ;
2929
30- this . bounds = new Phaser . Rectangle ( 0 , 0 , width , height ) ;
30+ this . boundsFluid = new Phaser . Rectangle ( 0 , 0 , width , height ) ;
31+ this . boundsFull = manager . bounds ;
32+ this . boundsNone = new Phaser . Rectangle ( 0 , 0 , width , height ) ;
3133
3234 /**
3335 * @property {Phaser.Point } position -
3436 * @readonly
3537 */
36- this . position = new Phaser . Point ( 0 , 0 ) ;
38+ this . positionFluid = new Phaser . Point ( 0 , 0 ) ;
39+ this . positionFull = new Phaser . Point ( 0 , 0 ) ;
40+ this . positionNone = new Phaser . Point ( 0 , 0 ) ;
3741
3842 /**
3943 * @property {Phaser.Point } scaleFactor - The scale factor based on the game dimensions vs. the scaled dimensions.
4044 * @readonly
4145 */
42- this . scaleFactor = new Phaser . Point ( 1 , 1 ) ;
43-
44- /**
45- * @property {Phaser.Point } scaleFactorInversed - The inversed scale factor. The displayed dimensions divided by the game dimensions.
46- * @readonly
47- */
48- this . scaleFactorInversed = new Phaser . Point ( 1 , 1 ) ;
46+ this . scaleFluid = new Phaser . Point ( 1 , 1 ) ;
47+ this . scaleFull = new Phaser . Point ( 1 , 1 ) ;
48+ this . scaleNone = new Phaser . Point ( 1 , 1 ) ;
4949
5050 this . ratioH = width / height ;
5151 this . ratioV = height / width ;
5252
5353 this . multiplier = 0 ;
5454
55- this . fitHorizontally = false ;
56- this . fitVertically = false ;
57-
5855 this . layers = [ ] ;
5956
6057} ;
@@ -70,58 +67,105 @@ Phaser.FlexGrid.prototype = {
7067 this . ratioH = width / height ;
7168 this . ratioV = height / width ;
7269
70+ this . scaleNone = new Phaser . Point ( 1 , 1 ) ;
71+
72+ this . boundsNone . width = this . width ;
73+ this . boundsNone . height = this . height ;
74+
7375 this . refresh ( ) ;
7476
7577 } ,
7678
77- createLayer : function ( ) {
79+ // Need ability to create your own layers with custom scaling, etc.
80+
81+ createFluidLayer : function ( ) {
82+
83+ var layer = this . game . add . group ( ) ;
84+
85+ // Override the position and scale so they point to our objects instead, this will keep them matched
86+ layer . position = this . positionFluid ;
87+ layer . scale = this . scaleFluid ;
88+
89+ this . layers . push ( layer ) ;
90+
91+ return layer ;
92+
93+ } ,
94+
95+ createFullLayer : function ( ) {
96+
97+ var layer = this . game . add . group ( ) ;
98+
99+ // Override the position and scale so they point to our objects instead, this will keep them matched
100+ layer . position = this . positionFull ;
101+ layer . scale = this . scaleFull ;
102+
103+ this . layers . push ( layer ) ;
104+
105+ return layer ;
106+
107+ } ,
108+
109+ createFixedLayer : function ( ) {
78110
79111 var layer = this . game . add . group ( ) ;
80112
81113 // Override the position and scale so they point to our objects instead, this will keep them matched
82- layer . position = this . position ;
83- layer . scale = this . scaleFactor ;
114+ layer . position = this . positionNone ;
115+ layer . scale = this . scaleNone ;
84116
85117 this . layers . push ( layer ) ;
86118
87119 return layer ;
88120
89121 } ,
90122
123+ reset : function ( ) {
124+
125+ for ( var i = 0 ; i < this . layers . length ; i ++ )
126+ {
127+ // Remove references to this class
128+ this . layers [ i ] . position = null ;
129+ this . layers [ i ] . scale = null ;
130+ }
131+
132+ this . layers . length = 0 ;
133+
134+ } ,
135+
91136 onResize : function ( width , height ) {
92137
93- this . refresh ( ) ;
138+ this . refresh ( width , height ) ;
94139
95140 } ,
96141
97142 refresh : function ( ) {
98143
99- // Now let's scale it
100-
101144 this . multiplier = Math . min ( ( this . manager . height / this . height ) , ( this . manager . width / this . width ) ) ;
102145
103- this . bounds . width = Math . round ( this . width * this . multiplier ) ;
104- this . bounds . height = Math . round ( this . height * this . multiplier ) ;
105-
106- // Max checks?
146+ this . boundsFluid . width = Math . round ( this . width * this . multiplier ) ;
147+ this . boundsFluid . height = Math . round ( this . height * this . multiplier ) ;
107148
108- this . scaleFactor . set ( this . bounds . width / this . width , this . bounds . height / this . height ) ;
109- this . scaleFactorInversed . set ( this . width / this . bounds . width , this . height / this . bounds . height ) ;
149+ this . scaleFluid . set ( this . boundsFluid . width / this . width , this . boundsFluid . height / this . height ) ;
150+ this . scaleFull . set ( this . boundsFull . width / this . width , this . boundsFull . height / this . height ) ;
110151
111- this . bounds . centerOn ( this . manager . bounds . centerX , this . manager . bounds . centerY ) ;
152+ this . boundsFluid . centerOn ( this . manager . bounds . centerX , this . manager . bounds . centerY ) ;
153+ this . boundsNone . centerOn ( this . manager . bounds . centerX , this . manager . bounds . centerY ) ;
112154
113- this . position . set ( this . bounds . x , this . bounds . y ) ;
155+ this . positionFluid . set ( this . boundsFluid . x , this . boundsFluid . y ) ;
156+ this . positionNone . set ( this . boundsNone . x , this . boundsNone . y ) ;
114157
115158 } ,
116159
117160 debug : function ( ) {
118161
119- this . game . debug . text ( "h: " + this . ratioH + " v: " + this . ratioV , 32 , 32 ) ;
120- this . game . debug . text ( this . scaleFactor , 32 , 64 ) ;
121- // this.game.debug.text(this.scaleFactorInversed, 32, 64+32);
122- // this.game.debug.geom(this.bounds);
162+ this . game . debug . text ( this . boundsFluid . width + ' x ' + this . boundsFluid . height , this . boundsFluid . x + 4 , this . boundsFluid . y + 16 ) ;
163+ this . game . debug . geom ( this . boundsFluid , 'rgba(255,0,0,0.9' , false ) ;
123164
124- } ,
165+ this . game . debug . text ( this . boundsNone . width + ' x ' + this . boundsNone . height , this . boundsNone . x + 4 , this . boundsNone . y + 16 ) ;
166+ this . game . debug . geom ( this . boundsNone , 'rgba(0,255,0,0.9' , false ) ;
167+
168+ }
125169
126170} ;
127171
0 commit comments