@@ -30,7 +30,7 @@ Phaser.Game = function (width, height, renderer, parent, state) {
3030 if ( typeof height === "undefined" ) { height = 600 ; }
3131 if ( typeof renderer === "undefined" ) { renderer = Phaser . RENDERER_AUTO ; }
3232 if ( typeof parent === "undefined" ) { parent = '' ; }
33- if ( typeof state === "undefined" ) { state = { } ; }
33+ if ( typeof state === "undefined" ) { state = null ; }
3434
3535 this . id = Phaser . GAMES . push ( this ) - 1 ;
3636 this . parent = parent ;
@@ -43,9 +43,7 @@ Phaser.Game = function (width, height, renderer, parent, state) {
4343
4444 console . log ( 'Phaser.Game' , width , height , renderer , parent ) ;
4545
46- // Pass 'state' to the StateManager?
4746 this . state = new Phaser . StateManager ( this , state ) ;
48- // this._tempState = state;
4947
5048 var _this = this ;
5149
@@ -237,12 +235,8 @@ Phaser.Game.prototype = {
237235
238236 console . log ( 'Phaser.Game boot' ) ;
239237
240- // Probably not needed any more
241- // var _this = this;
242-
243238 if ( ! document . body ) {
244239 window . setTimeout ( this . _onBoot , 20 ) ;
245- // setTimeout(Phaser.GAMES[_this.id].boot(parent, width, height), 13);
246240 }
247241 else
248242 {
@@ -252,6 +246,8 @@ Phaser.Game.prototype = {
252246 this . onPause = new Phaser . Signal ( ) ;
253247 this . onResume = new Phaser . Signal ( ) ;
254248
249+ this . isBooted = true ;
250+
255251 this . device = new Phaser . Device ( ) ;
256252 this . net = new Phaser . Net ( this ) ;
257253 this . math = Phaser . Math ;
@@ -267,7 +263,6 @@ Phaser.Game.prototype = {
267263 this . rnd = new Phaser . RandomDataGenerator ( [ ( Date . now ( ) * Math . random ( ) ) . toString ( ) ] ) ;
268264 // this.physics = new Phaser.Physics.PhysicsManager(this);
269265 this . plugins = new Phaser . PluginManager ( this , this ) ;
270- // this.state = new Phaser.StateManager(this, this._tempState);
271266
272267 this . load . onLoadComplete . add ( this . loadComplete , this ) ;
273268
@@ -278,68 +273,16 @@ Phaser.Game.prototype = {
278273
279274 console . log ( 'Phaser' , Phaser . VERSION , 'initialized' ) ;
280275
281- this . isBooted = true ;
282276 this . isRunning = true ;
283277 this . _loadComplete = false ;
284278
285- // this.raf = new Phaser.RequestAnimationFrame(this);
286- // this.raf.start();
287-
288- // boot sm
279+ this . raf = new Phaser . RequestAnimationFrame ( this ) ;
280+ this . raf . start ( ) ;
289281
290282 }
291283
292284 } ,
293285
294- /**
295- * Launch the game
296- * @param callbackContext Which context will the callbacks be called with.
297- * @param preloadCallback {function} Preload callback invoked when init default screen.
298- * @param createCallback {function} Create callback invoked when create default screen.
299- * @param updateCallback {function} Update callback invoked when update default screen.
300- * @param renderCallback {function} Render callback invoked when render default screen.
301- */
302- launch : function ( context , preload , create , update , render ) {
303-
304- /*
305- this.callbackContext = context;
306-
307- this.onPreloadCallback = preload || null;
308- this.onCreateCallback = create || null;
309- this.onUpdateCallback = update || null;
310- this.onRenderCallback = render || null;
311-
312- if (this.onPreloadCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null)
313- {
314- console.warn("Phaser cannot start: No preload, create, update or render functions given and no pending State found");
315- }
316- else
317- {
318- if (this.isBooted)
319- {
320- console.log('launch has set the callbacks and dom is booted so lets rock');
321-
322- this.startState();
323-
324- // if (this._pendingState)
325- // {
326- // this.switchState(this._pendingState, false, false);
327- // }
328- // else
329- // {
330- // this.startState();
331- // }
332-
333- }
334- else
335- {
336- console.log('launch has set the callbacks but cant start because the DOM isnt booted yet');
337- }
338- }
339- */
340-
341- } ,
342-
343286 /**
344287 * Called when the load has finished, after preload was run.
345288 */
@@ -351,12 +294,8 @@ Phaser.Game.prototype = {
351294
352295 this . state . loadComplete ( ) ;
353296
354- this . load . onLoadComplete . remove ( this . loadComplete , this ) ;
355-
356- // if (this.onCreateCallback) {
357- // this.onCreateCallback.call(this.callbackContext);
358- // // this.onCreateCallback.call(this);
359- // }
297+ // ?
298+ // this.load.onLoadComplete.remove(this.loadComplete, this);
360299
361300 } ,
362301
@@ -377,49 +316,33 @@ Phaser.Game.prototype = {
377316
378317 if ( this . _loadComplete )
379318 {
380- if ( this . onUpdateCallback )
381- {
382- this . onUpdateCallback . call ( this . callbackContext ) ;
383- }
319+ this . state . update ( ) ;
384320
385321 // this.world.postUpdate();
386322 this . plugins . postUpdate ( ) ;
387323 this . plugins . preRender ( ) ;
388324
389- if ( this . onPreRenderCallback )
390- {
391- this . onPreRenderCallback . call ( this . callbackContext ) ;
392- }
325+ this . state . preRender ( ) ;
393326
394327 // this.renderer.render();
395328 this . plugins . render ( ) ;
396329
397- if ( this . onRenderCallback )
398- {
399- this . onRenderCallback . call ( this . callbackContext ) ;
400- }
330+ this . state . render ( ) ;
401331
402332 this . plugins . postRender ( ) ;
403333 }
404334 else
405335 {
406336 // Still loading assets
407- if ( this . onLoadUpdateCallback )
408- {
409- this . onLoadUpdateCallback . call ( this . callbackContext ) ;
410- }
337+ this . state . loadUpdate ( ) ;
411338
412339 // this.world.postUpdate();
413340 this . plugins . postUpdate ( ) ;
341+
414342 this . plugins . preRender ( ) ;
415343 // this.renderer.render();
416344 this . plugins . render ( ) ;
417-
418- if ( this . onLoadRenderCallback )
419- {
420- this . onLoadRenderCallback . call ( this . callbackContext ) ;
421- }
422-
345+ this . state . loadRender ( ) ;
423346 this . plugins . postRender ( ) ;
424347 }
425348
@@ -430,15 +353,9 @@ Phaser.Game.prototype = {
430353 */
431354 destroy : function ( ) {
432355
433- this . callbackContext = null ;
434- this . onPreloadCallback = null ;
435- this . onLoadRenderCallback = null ;
436- this . onLoadUpdateCallback = null ;
437- this . onCreateCallback = null ;
438- this . onUpdateCallback = null ;
439- this . onRenderCallback = null ;
440- this . onPausedCallback = null ;
441- this . onDestroyCallback = null ;
356+ this . state . destroy ( ) ;
357+
358+ this . state = null ;
442359 this . cache = null ;
443360 this . input = null ;
444361 this . load = null ;
0 commit comments