CelerX Gaming SDK
Search…
⌃K

HTML5 Solo Game

By integrating with CelerX HTML5 Solo Game SDK, you can enable multi-player competitions for your solo HTML5 game. The competition result will be determined by the score each player gets in your solo game, and the one with a higher score will be the winner.
Example Project: Go Celer!
NOTE: Before integrating with CelerX Game SDK, please make sure that your game does not contain any remotely-fetched resources otherwise your game may not be properly loaded. All game resources must be loaded from local resources.

API Overview

celerx.ready()

Tell the CelerX app that the game UI is ready to be displayed
Best practice: choose the right moment to call celerx.ready() to display your game UI. At the beginning, the game usually has a loading period. If you do not feel comfortable showing the game UI to the user too early, you can wait till everything is rendered, then call celerx.ready(). This way, you do not need to implement a loading screen yourself, the “confirm ready” UI in CelerX mobile app will cover this “ugly” loading process for you.
Attention: celerx.ready() is only for loading necessary resources and preparing a “ready to go” UI before the game starts. Do not trigger any game start logic automatically in celerx.ready(). At this stage, the game should wait for the CelerX mobile app to trigger the game start logic in celerx.onStart(function()).

celerx.onStart(function())

  • function() is the callback function in your game code
Put your game start logic in the callback function and pass it as a parameter in celerx.onStart(function()). The CelerX mobile app will trigger your callback function when both players are ready to go.

celerx.getMatch()

Get the current match information, the result is a json object
celerx.getMatch();
Returned json example:
{
"matchId":"58702eb0-f5d2-4efa-9fca-9e31ca21a8cf",
"sharedRandomSeed":0.173629058,
"shouldLaunchTutorial":true,
"forceMute":false,
"currentPlayer":{
"index":1,
"id":"ali23",
"name":"Alice"
},
"players":[
{
"index":1,
"id":"ali23",
"name":"Alice"
},
{
"index":2,
"id":"bob98",
"name":"Bob"
}
]
}
  • matchId String
the current match id
  • sharedRandomSeed float
a float value between 0 and 1. You need to use sharedRandomSeed as the seed for any random number generation in your game that may affect the game result. All players in the same match will use the same random seed, which ensures competition fairness.
  • shouldLaunchTutorial boolean
a boolean value indicating whether in this match there is a tutorial for the user. If the value is true, it is usually the first time when user plays this game. You can add some tutorial UI in your game when the value is true. When the value is false, hide your tutorial UI. We highly recommend developers to use this flag to launch first-time game tutorial to provide the best game experience.
  • forceMute boolean
a boolean value indicating whether user wants to force mute the game audio. If the value is true, it means user wants to play game without game audio. E.g.: user would like to listen to his own background music from device, while playing the game. You should mute game audio at the beginning of the game. When the value is false, you can play game sound as usual.
  • currentPlayer Json
the current player who is playing the game
  • name String
a String value which can be used to display the player's nick name
  • id String
a String value which can be used as a unique user identifier on the CelerX platform
  • index int
an integer value indicating whether the player is player 1 or player 2 (only used in turn-based games)
  • players JsonArray
a list of players in the current match

celerx.submitScore(score)

  • score Int
an integer value to be used as parameter to submit the final score of the current player to CelerX platform

celerx.provideScore(int function())

  • function() is a callback function. This function should return an integer value, which is user’s current score in the match.
The CelerX mobile app will trigger the callback function when the mobile app needs to know the current score in the solo game. Use this API as soon as you have declared a currentScore variable for your solo game. Make sure to add a line of code to return the value of the current score inside the function. This API allows the mobile app to pull at anytime the current score.
celerx.provideScore(int function() {
console.log(“Mobile app is pulling current score:”, currentScore);
return currentScore;
})

celerx.onPause(function())

  • function() is a callback function in your game code.
The CelerX mobilbe app will trigger the callback when the app is switced from foreground to background. It is highly recommended to pause the game and show the game menu when this callback is triggered, to provide the best user experience.