Skip to content

Getting Started

Mat Hopwood edited this page Oct 2, 2020 · 9 revisions

Getting Started with IGX

IGX is based on the Facebook Instant Games (IG) SDK. You can find out more about this SDK at here. As the base functionality of IGX is based on FBInstant and is meant primarily as a way to deploy Instant games to web, IGX provides a like for like replacement of most of the SDK. There is a little set up to do beforehand, but once that's done, using IGX its just like using FBInstant.

The main object that provides the interface to IGX is called FBInstant. All calls go through this object to ensure that code remains compatible with Facebook Instant Games. There is additional functionality available within IGX that is not available for IG, this is accessible via the FBINstant.ext object. This will be covered later.

Pre-boot

Before we can begin calling methods of FBInstant we firstly need to decide and set up which back-ends we are going to use. FBInstant contains an object called options, which contains further sub object with objects for each sub system. We pass set up data to the back-end via these options. Lets take a look at a typical example:

if (FBInstant.ext !== undefined) // Make sure that IGX is available
{
    FBInstant.options.name = 'my_game_name';
    FBInstant.options.apiKey = "Xtralife api key";
    FBInstant.options.apiSecret = "xtralife api secret";
    FBInstant.options.devMode = "sandbox";
    FBInstant.options.shareOptions.shareURI = window.location.origin + window.location.pathname;	                
    FBInstant.options.adsOptions.appId = "App ID for ad network";
    FBInstant.options.analyticsOptions.trackingId = "Google analytics tracking ID";
}

Depending on which back-end you use, these options will differ.

Once options are set you can create instances of the service modules you would like to use, e.g.:

new GameService("xtralife");
new StorageService("xtralife");
new UserService("xtralife");
new LeaderboardsService("xtralife");
new MessagingService("xtralife");
new ReferralService("xtralife");
new ShareService("generic");
new AnalyticsService("google");
new AdsService("crazygames");
new PaymentsService("paypal");

If a vendor has been assigned to a specific service module then passing in the same vendor name will force the back-end assigned to that service module to be re-used. For example, "xtralife" in the above example will provide the back-end functionality for 6 services. Note that as the first 7 service modules use the same back-end and is the default, you can call the following to automatically take care of creating the first 7 modules for you, saving many lines of ugly code:

if (FBInstant.ext !== undefined) // Make sure that IGX is available
{
    FBInstant.createDefaultServices("xtralife");
}

Boot up

To start using IGX we use the same initialisation process as IG:

var fb_init = false;
FBInstant.initializeAsync().then(function()	{
    fb_init = true;
});

Load your resources at this point, when resources have finished loading we can start the game if fb_init is true, if it is not then we need to wait until it is then start the game:

FBInstant.startGameAsync().then(function()
{
    // Launch game
}).catch(function(e) {
    // Error occurred
});

Help keep this project alive by donating paypal

Clone this wiki locally