Follow the simply steps explained below, in 5 minute you are ready to test your game with the SDK integrated!
Probably you already have this installed in your PC/Mac but just in case here are the tutorial to setting up in environment for development:
- Mac Users can follow this guide: http://blog.teamtreehouse.com/install-node-js-npm-mac
- Windows Users can follow this one: http://blog.teamtreehouse.com/install-node-js-npm-windows (Some other of billions guides on the web anyway will be ok)
- Linux Users can simply follow the NodeJS guide https://nodejs.org/en/download/package-manager/
You should add this line to your file hosts ( How to edit my host file? )
127.0.0.1 local.www.gameasy.com
git clone https://github.com/docomodigital/game-sdk
npm install
Put the game in game-sdk/public/game/myfolder where myfolder could have any name you prefer
npm start
Go to http://local.www.gameasy.com:8080 All games currently available in the public > games directory will be show and can be started with the relative Play button
// index.html
// It's better to put the initialization in your index.html as soon as possible
GamifiveSDK.init({
lite: true,
menuPosition: 'TOP_LEFT' //'BOTTOM_RIGHT', 'TOP_RIGHT', 'BOTTOM_LEFT'
}); // lite false means without gameover
GamifiveSDK.loadUserData(function(userData) {
// UserData is null the first time or after a clearUserData() call
// The userData is associated with userid-gameid combination
// You can integrate this function with your assets loader
// for example in construct2 you can send a signal to the loader
// N.B. getDefaultUserData() implementation it's your implementation responsability
// and should return a javascript object
var initialState = userData ? userData : getDefaultsUserData();
initGame(initialState);
});
GamifiveSDK.onStartSession(function(){
// this will be called every time a start session is called
})
// When the user play:
GamifiveSDK.startSession();
// When the user finish to play
GamifiveSDK.endSession( { score: 123456789, level: 1 } );
// This will saves the state on our server and on local
// N.B. The object is just an example. You can structure it however you want
GamifiveSDK.saveUserData({ level1: { score: 123456789, unlocked: true } });
// The more games button is a floating action button that once clicked redirect the user
// to our portal. It's needed to show this button in your pause event
GamifiveSDK.showMoreGamesButton();
GamifiveSDK.showMoreGamesButton('TOP_LEFT')//'BOTTOM_RIGHT', 'TOP_RIGHT', 'BOTTOM_LEFT'
// On exit pause hide the more games button
GamifiveSDK.hideMoreGamesButton();
Inside index file remove/comment the line below if present:
<script id="gfsdk" src="http://s.motime.com/js/wl/webstore_html5game/gfsdk/dist/gfsdk.min.js"></script>
Our SDK integration calls can be anywhere in the code at the specific event (Game Start, Game Over, Game Pause, etc) The init and the load should be inside the index file but this is up to your code. Here is the list of our calls:
GamifiveSDK.init({ lite: true, menuPosition: 'TOP_LEFT' });
GamifiveSDK.loadUserData(function(resp) {});
GamifiveSDK.hideMoreGamesButton();
GamifiveSDK.startSession();
GamifiveSDK.showMoreGamesButton();
GamifiveSDK.saveUserData({ 'score' : score_var, 'level' : level_var });
GamifiveSDK.endSession({ 'score' : score_var, 'level' : level_var });
Before sending the package just put this tag in your head
<script id="gfsdk" src="http://s.motime.com/js/wl/webstore_html5game/gfsdk/dist/gfsdk.min.js"></script>
These are valid aliases too for game-sdk in window main scope
- GamefiveSDK
- DocomoSDK
- GamifiveSdk
- GamefiveSdk
Called when the data, saved with saveUserData, has been loaded from server
Type: Function
Parameters
userProgress
(Object | null)
Initialize the sdk
Parameters
initConfig
Object
Returns Promise
Returns the whole state!
Returns Object
Returns the number of the last level reached by user
Returns Number
Shows the menu|moregames button. call this function when in pause
Parameters
position
string? custom position
Hides the menu | moregames button call this function when on pause exit
Loads the arbitrary data from our server. Returns somenthing only for retrocompatibility. Since version >=2 must be called with the callback signature
Parameters
onLoadUserData
onLoadUserDataCb
SDK~onLoadUserData The callback that handles the response.
Save an arbitrary object on server and on local
Parameters
userDataInfo
Object
Clear the user data saved on local and on server. Use this function only under explicit user input
Redirect the browser to the game portal
Get the user avatar if any.
Returns Object avatarObj
Returns String avatarObj.src - the url of the avatar object
Returns String avatarObj.nickname - the name of the user
Get the userNickName if any. otherwise undefined
Register a function that will be called on each startSession call
Parameters
onStartSessionCallback
Function
Starts a session. If the init it's still in pending the session will start on init finished
Ends a session and calculate the session time. This function can be called without params. In this case only the session time is calculated. It can be called also with just the score and in this case the level is implicitly 1 this is useful for games without levels.
Parameters
scoreAndLevel
Object (optional, default{score:0,level:1}
)
Get the version object
Returns Object version
Returns String version.version - The commit string in semantic version syntax
Returns String version.build - The hash of the commit version refers
Returns if the sdk has been initialized
Returns Boolean