11/// <reference path="Phaser.ts" />
22/// <reference path="Game.ts" />
33/// <reference path="system/StageScaleMode.ts" />
4+ /// <reference path="system/screens/BootScreen.ts" />
5+ /// <reference path="system/screens/PauseScreen.ts" />
46
57/**
68* Phaser - Stage
@@ -43,6 +45,9 @@ module Phaser {
4345 this . scaleMode = StageScaleMode . NO_SCALE ;
4446 this . scale = new StageScaleMode ( this . _game ) ;
4547
48+ this . _bootScreen = new BootScreen ( this . _game ) ;
49+ this . _pauseScreen = new PauseScreen ( this . _game , width , height ) ;
50+
4651 document . addEventListener ( 'visibilitychange' , ( event ) => this . visibilityChange ( event ) , false ) ;
4752 document . addEventListener ( 'webkitvisibilitychange' , ( event ) => this . visibilityChange ( event ) , false ) ;
4853 window . onblur = ( event ) => this . visibilityChange ( event ) ;
@@ -52,7 +57,8 @@ module Phaser {
5257
5358 private _game : Game ;
5459 private _bgColor : string ;
55-
60+ private _bootScreen ;
61+ private _pauseScreen ;
5662
5763 public static ORIENTATION_LANDSCAPE : number = 0 ;
5864 public static ORIENTATION_PORTRAIT : number = 1 ;
@@ -63,6 +69,7 @@ module Phaser {
6369 public canvas : HTMLCanvasElement ;
6470 public context : CanvasRenderingContext2D ;
6571 public disablePauseScreen : bool = false ;
72+ public disableBootScreen : bool = false ;
6673 public offset : Point ;
6774 public scale : StageScaleMode ;
6875 public scaleMode : number ;
@@ -82,91 +89,48 @@ module Phaser {
8289 this . context . clearRect ( 0 , 0 , this . width , this . height ) ;
8390 }
8491
85- }
86-
87- public renderDebugInfo ( ) {
92+ if ( this . _game . isRunning == false && this . disableBootScreen == false )
93+ {
94+ this . _bootScreen . update ( ) ;
95+ this . _bootScreen . render ( ) ;
96+ }
8897
89- this . context . fillStyle = 'rgb(255,255,255)' ;
90- this . context . fillText ( Phaser . VERSION , 10 , 20 ) ;
91- this . context . fillText ( 'Game Size: ' + this . width + ' x ' + this . height , 10 , 40 ) ;
92- this . context . fillText ( 'x: ' + this . x + ' y: ' + this . y , 10 , 60 ) ;
98+ if ( this . _game . paused == true && this . disablePauseScreen == false )
99+ {
100+ this . _pauseScreen . update ( ) ;
101+ this . _pauseScreen . render ( ) ;
102+ }
93103
94104 }
95105
96- //if (document['hidden'] === true || document['webkitHidden'] === true)
97106 private visibilityChange ( event ) {
98107
99- //console.log(event);
100-
101108 if ( this . disablePauseScreen )
102109 {
103110 return ;
104111 }
105112
106- if ( event . type == 'blur' && this . _game . paused == false && this . _game . isBooted == true )
113+ if ( event . type === 'blur' || document [ 'hidden' ] === true || document [ 'webkitHidden' ] = == true )
107114 {
108- this . _game . paused = true ;
109- this . drawPauseScreen ( ) ;
115+ if ( this . _game . paused == false )
116+ {
117+ this . _pauseScreen . onPaused ( ) ;
118+ this . saveCanvasValues ( ) ;
119+ this . _game . paused = true ;
120+ }
110121 }
111122 else if ( event . type == 'focus' )
112123 {
113- this . _game . paused = false ;
124+ if ( this . _game . paused == true )
125+ {
126+ this . _pauseScreen . onResume ( ) ;
127+ this . _game . paused = false ;
128+ this . restoreCanvasValues ( ) ;
129+ }
114130 }
115131
116132 }
117133
118- public drawInitScreen ( ) {
119-
120- this . context . fillStyle = 'rgb(40, 40, 40)' ;
121- this . context . fillRect ( 0 , 0 , this . width , this . height ) ;
122-
123- this . context . fillStyle = 'rgb(255,255,255)' ;
124- this . context . font = 'bold 18px Arial' ;
125- this . context . textBaseline = 'top' ;
126- this . context . fillText ( Phaser . VERSION , 54 , 32 ) ;
127- this . context . fillText ( 'Game Size: ' + this . width + ' x ' + this . height , 32 , 64 ) ;
128- this . context . fillText ( 'www.photonstorm.com' , 32 , 96 ) ;
129- this . context . font = '16px Arial' ;
130- this . context . fillText ( 'You are seeing this screen because you didn\'t specify any default' , 32 , 160 ) ;
131- this . context . fillText ( 'functions in the Game constructor, or use Game.loadState()' , 32 , 184 ) ;
132-
133- var image = new Image ( ) ;
134- var that = this ;
135-
136- image . onload = function ( ) {
137- that . context . drawImage ( image , 32 , 32 ) ;
138- } ;
139-
140- image . src = this . _logo ;
141-
142- }
143-
144- private drawPauseScreen ( ) {
145-
146- this . saveCanvasValues ( ) ;
147-
148- this . context . fillStyle = 'rgba(0, 0, 0, 0.4)' ;
149- this . context . fillRect ( 0 , 0 , this . width , this . height ) ;
150-
151- // Draw a 'play' arrow
152- var arrowWidth = Math . round ( this . width / 2 ) ;
153- var arrowHeight = Math . round ( this . height / 2 ) ;
154-
155- var sx = this . centerX - arrowWidth / 2 ;
156- var sy = this . centerY - arrowHeight / 2 ;
157-
158- this . context . beginPath ( ) ;
159- this . context . moveTo ( sx , sy ) ;
160- this . context . lineTo ( sx , sy + arrowHeight ) ;
161- this . context . lineTo ( sx + arrowWidth , this . centerY ) ;
162- this . context . fillStyle = 'rgba(255, 255, 255, 0.8)' ;
163- this . context . fill ( ) ;
164- this . context . closePath ( ) ;
165-
166- this . restoreCanvasValues ( ) ;
167-
168- }
169-
170134 private getOffset ( element ) : Point {
171135
172136 var box = element . getBoundingClientRect ( ) ;
@@ -240,8 +204,6 @@ module Phaser {
240204 return Math . round ( Math . random ( ) * this . bounds . height ) ;
241205 }
242206
243- private _logo : string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAO1JREFUeNpi/P//PwM6YGRkxBQEAqBaRnQxFmwa10d6MAjrMqMofHv5L1we2SBGmAtAktg0ogOQQYHLd8ANYYFpPtTmzUAMAFmwnsEDrAdkCAvMZlIAsiFMMAEYsKvaSrQhIMCELkGsV2AAbIC8gCQYgwKIUABiNYBf9yoYH7n7n6CzN274g2IYEyFbsNmKLIaSkHpP7WSwUfbA0ASzFQRslBlxp0RcAF0TRhggA3zhAJIDpUKU5A9KyshpHDkjFZu5g2nJMFcwXVJSgqIGnBKx5bKenh4w/XzVbgbPtlIUcVgSxuoCUgHIIIAAAwArtXwJBABO6QAAAABJRU5ErkJggg==" ;
244-
245207 }
246208
247209}
0 commit comments