Does the HTML5 engine have any APIs I can interact with?

There is limited interaction a user can have with the HTML5 engine. The following functions are available:

gse.pauseGame(); // Pauses the Game

gse.playGame(); // Resumes the Game

gse.resetGame(); // Resets the Game

gse.getGameVolume(); // Gets the engine volume

On the sample-index.html file provide, inside the gse.ready callback function, you will see a playerDelegate object which has 3 delegate functions defined. These two actually trigger on engine events:

onLoadingBegin = function() { /* define what you want to happen while the engine is loading a scene */ }

onLoadingEnd = function() { /* define what you want to happen when the engine is done loading a scene */ }

You can also add callbacks for the following actions:

onCurrentSceneChanged = function(sceneKey, scenename) { /* define what extra actions to take when the scene changes. good for analytics or ads */

onShowBannerShow = function(position[‘top’|’bottom’]) { /* define what to do when the show banner behavior is triggered */

onTweetSheet = function(message, editable, image) { /* Define what happens when the tweet sheet behavior is invoked */ }

You can also write functionality to control the volume of the game inside the gse.ready callback.  Inside that callback you can call the following two functions:

gse.setGameVolume(engine, volume[0-1]); // Sets the volume for the whole game. Must be called where the engine context is available. This can be hooked up in the gse.ready callbackback function.  This must happen inside the gse.ready callback, because you can only set the volume after the engine has initialized.

onEndGame(); // Called when the end game behavior is triggered.

onIAPBuyItem(itemInfo) //  itemInfo: {itemID, consumable, name, price, state}. Return a promise that rejects if the purchase fails and resolves with the following json object: {buyerCancelled: (true || false), purchaseComplete: (true || false)}.

onIAPRestoreItems() // Returns a promise. Resolves with purchases object. Purchases is an array of objects containing the key itemID for all items purchased.

onIAPConsumeItem (itemInfo) // itemInfo: {itemID, consumable, name, price, state}. Return a promise that rejects if the purchase fails and resolves if the purchase is a success.

onIAPRequestPurchaseData() // Promise that resolves successful with itemInfo (see onIAPBuyItem) or rejects unsuccessfully.

onShowBannerShow() // Called when Show Banner Ad action is triggered

onGameCenterLogin() // Called when Game Service Login is triggered. Return a promise. If resolve is called, Platform Connected will be set to true.

onGameCenterPostScore(score, leaderboard) // No promise, just do what you will with the score and leaderboard name.

onGameCenterShowAchievements() // Called when the Show Achievements action is triggered.

onGameCenterResetAchievements() // Called when the Reset Achievements action is triggered.

onGameCenterUpdateAchievement (identifier, percentageComplete) // Called when Update Achievement is called.

onGameCenterShowLeaderboard (identifier) // Called when Show Leaderboard action is triggered.

onLogDebuggingStatement (text, entity) // Called when log Debug Statement action is triggered.


Was this article helpful?