Hello rockstars & welcome to the GamePix SDK Bible!
Follow some easy steps for a perfect integration of your game in our platform.
First: add our test library to your index.html file. We suggest you call the remote resource instead of downloading it.
<head>
...
<title>Your Game's Title</title>
<script src="https://gamepix.blob.core.windows.net/gpxlib/dev/gamepix.js"></script>
...
</head>
Under this object you must register functions that GamePix will call during your game lifetime.
GamePix.on.pause
Insert here the code to pause your game: not only the gameplay (action, sound, animations) but also the touchscreen input (everything must be freezed!)
GamePix.on.pause = function(){
//insert here your code to pause gameplay
}
GamePix.on.resume
Insert here the code that allows your game to be resumed: back to action!
GamePix.on.resume = function(){
//insert here your code to resume gameplay
}
GamePix.on.soundOn
Here goes the code to turn sound ON
GamePix.on.soundOn = function(){
//insert here your code to turn ON sound in your game
}
GamePix.on.soundOff
Here goes the code to completely turn sound OFF
GamePix.on.soundOff = function(){
//insert here your code to turn OFF sound in your game
}
GamePix.game.gameLoading(int)
Call this function when your game is loading. The int value to pass must be between 0 and 100.
/**
* percentage {int} [0 - 100]
*/
GamePix.game.gameLoading(percentage);
GamePix.game.gameLoaded(callback)
Call this function when the game is completely loaded and the next action to trigger is the game's start. Be sure that the audio of the game will start only after GamePix.game.gameLoaded is fired!
/**
* callback {function}
*/
GamePix.game.gameLoaded(function(){
//here the code to continue to main menu & start the audio of your game
});
GamePix.game.ping(type,object)
Use this function to tell GamePix when a level is completed or when the game's over, according to the logic of your game.
e.g. You won't have levels in endless games, but just the game over.
Please also add to this function an object where scores, levels reached, and achievements (if provided) are stored.
/**
* type {string} ['level_complete','game_over']
* object {object}
* level {string}
* score {int}
* achievements {object}
*/
GamePix.game.ping('level_complete', {score : score, level : level, achievements : {/*INSERT HERE IF AVAILABLE*/} });
GamePix.game.ping('game_over', {score : score, level : level, achievements : {/*INSERT HERE IF AVAILABLE*/} });
// Example A) if your games provides just levels, pass {score : 0, level : "current level"}
// Example B) if your games provides just scores, pass {score : actualScore, level : "main"}
// Example C) if your games provides both, pass {score : actualScore, level : "current level"}
// Example D) if your games provides also achievements pass {level : ..., score : ...}
N.B.1: When GamePix.game.ping is triggered, we are going to pause for a few seconds, and then resume sound and gameplay with the functions you previous registered at point 2 of the GamePix API Bible.
GamePix.localStorage.setItem(key,value)
Call this function for save data in the GamePix localStorage instead of window.localStorage
/**
* key {string}
* value {number | string}
*/
GamePix.localStorage.setItem(key, value);
GamePix.localStorage.getItem(key)
Call this function for get data from the GamePix localStorage
/**
* key {string}
*/
GamePix.localStorage.getItem(key);
GamePix.localStorage.removeItem(key)
Call this function remove data from the GamePix localStorage
/**
* key {string}
*/
GamePix.localStorage.removeItem(key);
OPTIONAL
GamePix.game.customLoading(bool)
This is an optional method that allows you to show a wait-till-loaded message if your game is downloading assets or if there are some kind of background operations that need to freeze the game and/or the user experience between levels. This function is not mandatory: use it just in case your game doesn't have such type of UI already.
/**
* bool {boolean}
*/
GamePix.game.customLoading(bool);
// Example A) GamePix.game.customLoading(true); -> show 'Wait' screen
// Example B) GamePix.game.customLoading(false); -> remove 'Wait' screen
IMPORTANT: If you want to join the GamePix premium program (more revenues) provide your games with multilanguage feature. Don't worry, you don't have to translate your texts, GamePix will do that for
you!
How does it work?
your-texts-in-english ---------------> GAMEPIX
IMPORTANT: your-texts-in-english are both textual strings in your code (e.g. var play = "play now!";) and texts inside your sprites/images.
YOU <--------------- your-texts-translated
GamePix.lang()
Executing GamePix.lang() will give you the language of the browser or the language passed in query string, e.g. : (index.html?lang=es ----> GamePix.lang() = 'es')
So in your code, when you're loading your assets/text, check for the GamePix.lang()
var possibleLanguagesInYourGames = ['en','fr','it','de','ru','es','pt','nl','tr','zh','ko','ja','ar'];
var askedLanguage = possibleLanguagesInYourGames.indexOf(GamePix.lang());
var defaultLanguage = 'en';
if(askedLanguage != -1){
defaultLanguage = GamePix.lang();
}