Plugin Documentation

This plugin makes your game playable on Instant Games.

API documentation

To learn how to use Instant Games SDK, take a look at the official API documentation.

Example game

You can download complete game template for Instant Games. Includes interstitial ad, leaderboard and player data. Fully commented source code.

Tutorials

Check out Instant Games tutorials.

Initializing

This plugin will initialize the Instant Games SDK automatically, so you don't need to worry about using initializeAsync or startGameAsync commands. Once the game enters into your start scene, all FBinstant features will be ready to use.

game.createScene('Main', {
    init: function() {
        var playerName = FBInstant.player.getName();

        // Load leaderboard
        FBInstant.getLeaderboardAsync('highscore')
        .then(function(leaderboard) {
            // Leaderboard loaded
        })
        .catch(function(error) {
            // Error
        });
    }
});

Profile photos

You can load and display profile photos with PlayerPhoto class. It's special version of Sprite class, which will resize the photo right after it's loaded (this is recommended because profile photos in Facebook can be different sizes). For example, if you want to show player's photo in size of 200x200:

// Load profile photo from photoUrl and resize it to 200x200.
var photo = new game.PlayerPhoto(photoUrl, 200);
photo.addTo(this.stage);

Player photo

You can also create circle version of the photo with third parameter.

// Load profile photo from photoUrl, resize it to 200x200 and mask into circle shape.
var photo = new game.PlayerPhoto(photoUrl, 200, true);
photo.addTo(this.stage);

Player photo

Current player's photo will be always preloaded on the startup with id playerPhoto.

// Show current player's photo in size of 200x200
var photo = new game.PlayerPhoto('playerPhoto', 200);
photo.addTo(this.stage);

Configuration

For custom updates, you need to create a configuration file called fbapp-config.json and place it in the root of your project.

You can also define the configuration in game.config and the fbapp-config.json file will be generated and included automatically in your project package when uploading to Facebook from Panda 2.

game.config = {
    instantGames: {
        config: {
            instant_games: {
                platform_version: 'RICH_GAMEPLAY',
                custom_update_templates: {
                    play_turn: {
                        example: 'Edgar played their move'
                    }
                }
            }
        }
    }
};

Read more about bundle-based configuration.

Debugging

When launching your game from Messenger or Facebook, variable game.device.instantGames will be set to true. That way you can define attributes that are applied only when using Instant Games.

game.config = {
    instantGames: {
        system: {
            resize: true // Use resize only on Instant Games
        }
    }
};

When running your game in Panda 2, the plugin will automatically load mockup version of the SDK. This allows you to test all the functionality without having to upload every time you make changes.

You can change mockup SDK debug settings in your game.config.

game.config = {
    instantGames: {
        debug: {
            verbose: true, // Turn on console messages
            context: 0, // Change current context
            player: 1 // Change current player
        }
    }
};

By default, there are four different contexts and players defined for debugging. You can switch between different ones by changing the context and player values inside the debug object.

You can also set custom entryPointData that is returned from FBinstant.getEntryPointData().

game.config = {
    instantGames: {
        debug: {
            entryPointData: {
                foo: 'bar' // Custom entryPointData
            }
        }
    }
};

Testing and Uploading

Upload

Once the game is ready for testing, you can export it directly to Instant Games.

Changelog

1.3.3

  • Updated SDK to 6.2

1.3.2

  • Added game.onFBInstantStarted function
  • Fixed PlayerPhoto loading when using with PixiJS plugin

1.3.1

  • Fixed to load Instant Games SDK from Facebook

1.3.0

  • Added PlayerPhoto class

1.2.0

  • Added InstantAd class

1.1.0

  • Added game.onFBInstantInited function
  • Optimized loading
  • Updated SDK to 6.1