@@ -29,21 +29,31 @@ Phaser.FrameDebugger = function (game) {
2929 this . count = 0 ;
3030 this . max = 1 ;
3131
32+ // Consts
33+ this . START = 0 ;
34+ this . STOP = 1 ;
35+ this . CANVAS_CLEAR = 2 ;
36+ this . CANVAS_BLENDMODE = 3 ;
37+ this . CANVAS_MASK_PUSH = 4 ;
38+ this . CANVAS_MASK_POP = 5 ;
39+ this . CANVAS_RENDER_SPRITE = 6 ;
40+
3241} ;
3342
43+
3444Phaser . FrameDebugger . prototype = {
3545
3646 // Called at the start of Game.updateRender
3747 start : function ( ) {
3848
39- this . frame = [ Date . now ( ) ] ;
49+ this . frame = [ { type : this . START , time : Date . now ( ) } ] ;
4050
4151 } ,
4252
4353 // Called at the end of Game.updateRender
4454 stop : function ( ) {
4555
46- this . frame . push ( Date . now ( ) ) ;
56+ this . frame . push ( { type : this . STOP , time : Date . now ( ) } ) ;
4757
4858 this . log . push ( this . frame ) ;
4959
@@ -58,31 +68,36 @@ Phaser.FrameDebugger.prototype = {
5868
5969 cr : function ( ) {
6070
61- this . frame . push ( 'Canvas.Render' ) ;
71+ this . frame . push ( { type : this . CANVAS_CLEAR } ) ;
6272
6373 } ,
6474
6575 cb : function ( mode ) {
6676
67- this . frame . push ( 'Set Blend Mode' , mode ) ;
77+ this . frame . push ( { type : this . CANVAS_BLENDMODE , mode : mode } ) ;
6878
6979 } ,
7080
7181 cs : function ( texture , width , height , res ) {
7282
73- this . frame . push ( 'Sprite.Render' , texture , width , height , res ) ;
83+ this . frame . push ( {
84+ type : this . CANVAS_RENDER_SPRITE ,
85+ texture : texture ,
86+ width : width , height : height ,
87+ resolution : res
88+ } ) ;
7489
7590 } ,
7691
7792 cm : function ( mask ) {
7893
79- this . frame . push ( 'Mask Push' , mask ) ;
94+ this . frame . push ( { type : this . CANVAS_MASK_PUSH , mask : mask } ) ;
8095
8196 } ,
8297
8398 cmo : function ( ) {
8499
85- this . frame . push ( 'Mask Pop' , Date . now ( ) ) ;
100+ this . frame . push ( { type : this . CANVAS_MASK_POP } ) ;
86101
87102 } ,
88103
@@ -111,43 +126,98 @@ Phaser.FrameDebugger.prototype = {
111126 // Called at the end of Game.updateRender if count = max
112127 finish : function ( ) {
113128
129+ console . log ( this . log ) ;
130+
114131 this . on = false ;
115132
116133 this . win = window . open ( 'about:blank' , 'FrameDebugger' ) ;
117134
118- // Add a title and a little css
119- this . win . document . title = 'FrameDebugger Output' ;
120-
121- var head = this . win . document . head . style ;
122-
123- head . backgroundColor = '#383838' ;
124- head . fontFamily = 'sans' ;
125- head . fontSize = '14px' ;
126- head . color = '#b4b4b4' ;
135+ var content = '<!DOCTYPE html>'
136+ + '<head><title>FrameDebugger Output</title>'
137+ + '<style>'
138+ + 'body {'
139+ + ' background: #383838;'
140+ + ' color: #b4b4b4;'
141+ + ' font-family: sans-serif;'
142+ + ' font-size: 12px;'
143+ + '}'
144+ + 'h2 {'
145+ + ' border-top: 1px dashed white;'
146+ + ' margin-top: 32px;'
147+ + '}'
148+ + '.xstrip {'
149+ + ' background: #4a4a4a;'
150+ + ' display: flex;'
151+ + ' flex-flow: row nowrap;'
152+ + '}'
153+ + '</style>'
154+ + '</head>'
155+ + '<body>'
156+ + '<h1>FrameDebugger</h1>' ;
157+ + '</body></html>' ;
158+
159+ this . win . document . open ( 'text/html' , 'replace' ) ;
160+ this . win . document . write ( content ) ;
161+ this . win . document . close ( ) ;
127162
128163 var body = this . win . document . body ;
129164
130- var h1 = document . createElement ( 'h1' ) ;
131- h1 . textContent = 'FrameDebugger Output' ;
132-
133- body . appendChild ( h1 ) ;
134-
135165 for ( var f = 0 ; f < this . log . length ; f ++ )
136166 {
137- var h = document . createElement ( 'p' ) ;
138- h . textContent = "Frame " + f ;
139- body . appendChild ( h ) ;
167+ var frame = this . log [ f ] ;
168+
169+ this . addTag ( body , 'h2' , 'Frame ' + f ) ;
170+
171+ var box = this . addTag ( body , 'ol' , null , 'strip' ) ;
140172
141- for ( var i = 0 ; i < this . log [ f ] . length ; i ++ )
173+ for ( var i = 0 ; i < frame . length ; i ++ )
142174 {
143- var t = document . createElement ( 'p' ) ;
144- t . textContent = this . log [ f ] [ i ] ;
145- body . appendChild ( t ) ;
175+ var t = frame [ i ] ;
176+
177+ switch ( t . type )
178+ {
179+ case this . START :
180+ this . addTag ( box , 'li' , 'Frame Start @ ' + t . time ) ;
181+ break ;
182+
183+ case this . CANVAS_RENDER_SPRITE :
184+ this . addTag ( box , 'li' , 'Sprite (' + t . width + ' x ' + t . height + ')' ) ;
185+ break ;
186+
187+ case this . STOP :
188+ var duration = t . time - frame [ 0 ] . time ;
189+ this . addTag ( box , 'li' , 'Frame Stop @ ' + t . time ) ;
190+ this . addTag ( box , 'li' , 'Frame Duration ' + duration + 'ms' ) ;
191+ break ;
192+ }
146193 }
147194 }
148195
149- // console.log(this.log);
150- // debugger;
196+ } ,
197+
198+ addImg : function ( parent , img ) {
199+
200+ parent . appendChild ( img . cloneNode ( true ) ) ;
201+
202+ } ,
203+
204+ addTag : function ( parent , tag , content , style ) {
205+
206+ var e = this . win . document . createElement ( tag ) ;
207+
208+ if ( content )
209+ {
210+ e . textContent = content ;
211+ }
212+
213+ if ( style )
214+ {
215+ e . className = style ;
216+ }
217+
218+ parent . appendChild ( e ) ;
219+
220+ return e ;
151221
152222 }
153223
0 commit comments