Phaser: Add a callback function after adding a scene

Created on 1 Feb 2019  路  2Comments  路  Source: photonstorm/phaser

Hey! Adding a scene to the game and then trying to get the scene immediately returns undefined.

game.scene.add('Dialogue', Dialogue);
game.scene.getScene('Dialogue');
// Returns undefined

If we could have a function that is called after the scene is done being added that would be nice.

Most helpful comment

Did you make sure the game is entirely booted at the time of the check?

Here is an example of the method you could use:

var game = new Phaser.Game({
    callbacks: {
        postBoot: function(game) {
            var upAndRunningScene = game.scene.getScene('Dialogue');
            //Should be OK here!
        }
    }
});

game.scene.add(
    'Dialogue',
    Dialogue,
    true
);

All 2 comments

Did you make sure the game is entirely booted at the time of the check?

Here is an example of the method you could use:

var game = new Phaser.Game({
    callbacks: {
        postBoot: function(game) {
            var upAndRunningScene = game.scene.getScene('Dialogue');
            //Should be OK here!
        }
    }
});

game.scene.add(
    'Dialogue',
    Dialogue,
    true
);

Oh my gosh I didn't know about that callback config. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samme picture samme  路  3Comments

cncolder picture cncolder  路  4Comments

BigZaphod picture BigZaphod  路  4Comments

halilcakar picture halilcakar  路  4Comments

lilijreey picture lilijreey  路  4Comments