Navigation

Part 3 - initializeAsync

Before we can do anything we need to wait for the Instant Games SDK initializeAsync promise to resolve. We shouldn't even create an instance of our game until this has happened. So the best thing to do is to wrap it around your game configuration.

We'll do this in a file called boot.js:

FBInstant.initializeAsync().then(function() {

    var config = {
        type: Phaser.AUTO,
        width: window.innerWidth,
        height: window.innerHeight
    };

    new Phaser.Game(config);

});

This is a minimal game configuration but it demonstrates how you should create your game instance after the promise resolves and not before. This is actually the only time you will need to interact with the Instant Games SDK directly, as all other operations can be handled by the plugin.

When the promise resolves, your game will be created and run through its usual boot process. In the code above you'll see we haven't defined any Scene's yet, nor did we include any code for them in the html file, which we'll do in the next part.