Getting Started with GamePix SDK Integration Process for Construct 2

This section contains all the steps you need to do in order to properly integrate your Game with GamePix SDK and Construct 2.

Before you start integrating the SDK methods inside your Game, here are a few things you need to check:

  • Be sure that also Functions object is imported in your project.Function object

1. Install the Plugin

Download the plugin from here: https://integration.gamepix.com/sdk/plugins/c2/latest/gamepix-sdk.c2addon.

Important: You're going to add the actual SDK script after you export the game, in the index.html file (see step 4.2 of this guide).

Don't copy GamePix SDK methods code anywhere else in your game.

To install it drag and drop the file inside Construct 2 window. Once done you should see a confirm popup:

Import Gpx Plugin to Construct 2

After that you have to insert the plugin in order to have it available:

Add Gpx Plugin in the project scope 2nd stepAdd Gpx Plugin in the project scope 3nd step

Once done you can start implementing the methods of the GamePix SDK.

2. Add Methods

GamePix.loading

This method is automatically implemented when you import the plugin itself. To check that is working, when you preview the game, you have to see a badge on the top of the screen which notifies the current loading values.

GamePixSDK.loading is sent automatically

GamePix.loaded

This event notifies that your game is ready to start but the code to make it really starts is inside the callback function loadedExecuted.

So here's a quick recap of how the flow should be:

This is the flow when game loads

As you can see you previously send an event via GamePixSDK.loaded and then you listen the response through function "loadedExecuted". Here's a quick screenshot of these two methods: When the game has completed to load all assets and is correctly initialized (e.g. previous state and/or global variables) trigger the GamePix.loaded but don't start the game.

When game is ready to start send this event.

When you receive the call from function named loadedExecuted you can actually starts the game.

When function loadedExecuted is called, really starts the game

GamePix.gameAction

Trigger GamePix.gameAction() upon the first user-input like a keystroke or mouseclick every time the user is beginning a gameplay. Don't call this event when you're in the menu.

Add the action gameAction

When the event is fired while testing a badge on the top of the window will be showed to notify that event has been correctly implemented.

When the action is fired there's a feedback from the game

GamePix.gameStop

Trigger a gameplayStop() when the gameplay stops and is not interactive anymore.

Add the action gameStop

When the event is fired while testing a badge on the top of the window will be showed to notify that event has been correctly implemented.

When the action is fired there's a feedback from the game

GamePix.updateScore

Call this function every time there's a score update inside the Game. The function accepts only numbers.

Add the action updateScoreSet the updateScore param

When the event is fired while testing a badge on the top of the window will be showed to notify that event has been correctly implemented.

Set the action updateScore

GamePix.updateLevel

Call this function every time the user gets to a new level. The function accepts only numbers.

We're not showing screenshots of this function because the game we're using as test doesn't have levels. However the steps to use and check it are the same for updateScore but instead of score you need to pass the reached level.

GamePix.happyMoment

Send to the SDK if a particular "Happy Moment" just happened in your Game. It could be the unlocking of a special item, or triggering a cool event in the Game.

Add the action happyMoment

When the event is fired while testing a badge on the top of the window will be showed to notify that event has been correctly implemented.

Check the action happyMoment

GamePix.rewardAd

This function will ask SDK to show a Reward Ad which returns a call to function assignReward or denyReward if the reward has to be assigned or not.

Add the action rewardAd

Once added the action, don't forget to register the callback functions to assign or deny the reward as shown here:

Add the function assignReward

Finally, to check that is working as expected, in your preview you'll see a dialog which asks to assign or not the reward.

Check the function rewardAd

GamePixSDK.lang

If your game has localized texts you can check the current language asking which value is:

Assign the value from GamePixSDK.lang to a variable

possible values are those ones ['ar','zh','nl','en','fr','de','it','ja','ko','pl','pt','ru','es','tr']. If your games just use English you can skip this part.

3. Storage

To save and retrieve your game progress use the GamePix SDK LocalStorage functionalities.

GamePix.setItem

Use setItem to save a value inside GamePix.localStorage object. It accepts only string for key and value.

Save an item in GamePix localStorage

GamePixSDK.getItem

To retrieve a stored item you have to use GamePixSDK.getItem expression. NB this will return the string value "null" if the current searched item doesn't exist.

Retrieve a value in GamePix.localStorage

GamePixSDK.removeItem

Remove item is similar to setItem usage.

4. Wrap-up & Test

Once you're ready with the SDK implementation you're to do the following steps.

1. Export your game

2. Add inside the generated index.html file the SDK javascript tag as shown below:

Code
<head>
  ...
  <script src="https://integration.gamepix.com/sdk/v3/gamepix.sdk.js"></script>
  ...
</head>

3. Test the game inside GamePix Test Tool to see if all requirements are satisfied.

GamePix Test Tool