@@ -24,6 +24,12 @@ Phaser.StateManager.prototype = {
2424 */
2525 _pendingState : null ,
2626
27+ /**
28+ * Flag that sets if the State has been created or not.
29+ * @type {Boolean }
30+ */
31+ _created : false ,
32+
2733 /**
2834 * The state to be switched to in the next frame.
2935 * @type {Object }
@@ -257,6 +263,8 @@ Phaser.StateManager.prototype = {
257263 {
258264 this . onCreateCallback . call ( this . callbackContext ) ;
259265 }
266+
267+ this . _created = true ;
260268 }
261269 else
262270 {
@@ -275,6 +283,8 @@ Phaser.StateManager.prototype = {
275283 this . onCreateCallback . call ( this . callbackContext ) ;
276284 }
277285
286+ this . _created = true ;
287+
278288 this . game . loadComplete ( ) ;
279289 }
280290
@@ -336,6 +346,7 @@ Phaser.StateManager.prototype = {
336346 this . onShutDownCallback = this . states [ key ] [ 'shutdown' ] || this . dummy ;
337347
338348 this . current = key ;
349+ this . _created = false ;
339350
340351 this . onInitCallback . call ( this . callbackContext ) ;
341352
@@ -345,22 +356,15 @@ Phaser.StateManager.prototype = {
345356
346357 // console.log('Phaser.StateManager.loadComplete');
347358
348- if ( this . onCreateCallback ) {
359+ if ( this . _created == false && this . onCreateCallback )
360+ {
349361 // console.log('Create callback found');
350362 this . onCreateCallback . call ( this . callbackContext ) ;
363+ this . _created = true ;
351364 }
352365
353366 } ,
354367
355- loadUpdate : function ( ) {
356-
357- if ( this . onLoadUpdateCallback )
358- {
359- this . onLoadUpdateCallback . call ( this . callbackContext ) ;
360- }
361-
362- } ,
363-
364368 loadRender : function ( ) {
365369
366370 if ( this . onLoadRenderCallback )
@@ -372,9 +376,16 @@ Phaser.StateManager.prototype = {
372376
373377 update : function ( ) {
374378
375- if ( this . onUpdateCallback )
376- {
377- this . onUpdateCallback . call ( this . callbackContext ) ;
379+ if ( this . _created && this . onUpdateCallback )
380+ {
381+ this . onUpdateCallback . call ( this . callbackContext ) ;
382+ }
383+ else
384+ {
385+ if ( this . onLoadUpdateCallback )
386+ {
387+ this . onLoadUpdateCallback . call ( this . callbackContext ) ;
388+ }
378389 }
379390
380391 } ,
0 commit comments