Advanced usage

martinzakovec edited this page Nov 2, 2018 · 41 revisions

GAMEE framework provides also other functionalities that might be helpful. Using them is optional.


gamee.gameInit

In order to use some of the described functions, you must declare them first during gameInit in the gameCapabilities array. Allowed values are "saveState", "replay", "ghostMode","socialData","playerData","share","logEvents","rewardedAds" and "coins".

Passing capabilities example

var capabilities = ["saveState", "replay", "ghostMode", "socialData","playerData","share",
"logEvents","rewardedAds","coins"];

// signature: controller, controllerOptions, gameCapabilities, callback
gamee.gameInit("FullScreen", {}, capabilities, function(error, data) {
    if(error !== null)
        throw error;

    var myController = data.controller;
    var sound = data.sound;

    // based on game capabilities, you will obtain additional data
    var saveState = data.saveState;  // contains data you previously saved
    var replayData = data.replayData;
    var socialData = data.socialData;
    var platform = data.platform; // contains the platform the player is using
                                  // it could be "android","ios","web","mobile_web"
    var locale = data.locale; // contains the country and the language of the player
                              // for example "en_US","es_MX","pt_BZ"...
    var gameContext = data.gameContext; // contains the context of the game it could 
                                        // be "normal" or "battle"
    var initData = data.initData; // json received if a player access the game through 
                                  // a post made with the "gamee.share" function


... // your code that should make game ready
});

gamee.updateScore

updateScore can be used to send ghost score. Then score of the ghost is updated instead of score of the player. This signature can be used only in game with active ghost mode.

Passing ghost score

// signature score, ghostSign, callback
gamee.updateScore(10, true, function(error) {
    if(error !== null)
        throw error;
});

gamee.gameSave

  • saveState -string- Data you want to store from the game.

*Requires declared capability "saveState" during gamee.Init

Simplest usage

gamee.gameSave("Data you want to save");

Complete usage

If opt_share param is true, platform will trigger screen asking player to share the progress with his actual score. The game must be paused during this process. The game continues when it receives a resume message.

var dataToSave = { 
    life: 95,
    score: 150
};

// Signature data, opt_share (default false), opt_callback
gamee.gameSave(JSON.stringify(dataToSave), true, function(error) {
    if(error !== null)
        throw error;
});

gamee.requestSocial

Will get more social data about Gamee players. If the player is not logged in then the parameter data.socialData.player will be empty.

*Requires declared capability "socialData" during gamee.Init

Complete usage

gamee.requestSocial(function (error, data) {
    if (data && data.socialData && data.socialData.friends) {
        data.socialData.friends.forEach(function (friend) {
            console.log(friend);
            // { name : "playerName", avatar : "url?", highScore: 1000 }
        }
    }

    if (data && data.socialData && data.socialData.player) {
        console.log(data.socialData.player)
        // {name:"playerName", highScore:1000, avatar:url, userID: 123456, coins:1000}
    }
});

gamee.requestPlayerData

Will get information about the current logged in player.

*Requires declared capability "playerData" during gamee.Init

Complete usage

gamee.requestPlayerData(function (error, data) {

    if (data && data.player) {
        console.log(data.player)
        // {name:"playerName", highScore:1000, avatar:url, userID: 123456, coins:1000}
    }
});

gamee.requestPlayerReplay

Will get information for Replay Mode.

*Requires declared capability "replay" during gamee.Init

Parameters

  • userID -number- The unique ID of the player you want to get the Replay Data.

Complete usage

gamee.requestPlayerReplay(usedID,function (error, data) {

    if (data) {
        var replayData = data.replayData.data
        var variant = data.replayData.variant
        // developer should use this data according to the game
    }
});

gamee.requestPlayerSaveState

Will get save state of specific user.

Parameters

  • userID -number- The unique ID of the player you want to get the Save State.

*Requires declared capability "saveState" during gamee.Init

Complete usage

gamee.requestPlayerSaveState(usedID,function (error, data) {

    if (data && data.saveState) {
        var saveState = data.saveState
        // developer should use this data according to the game
    }
});

gamee.logEvent

Events that the developer can store so he would be able to see statistics of the game.

Parameters

  • eventName -string- The name of the event, shouldn´t be longer than 24 characters.
  • eventValue -string- The value of the event

*Requires declared capability "logEvents" during gamee.Init

Complete usage

gamee.logEvent("eventName","eventValue");

gamee.loadRewardedVideo

Function used to load rewarded ads inside the game. Using this function, you will know if there is any ad available and ready to be shown.

*Requires declared capability "rewardedAds" during gamee.Init

Complete usage

var isVideoReady = false
gamee.loadRewardedVideo(function(error,data){
    if(data && data.videoLoaded){
        // video loaded and is ready to be shown using gamee.showRewardedVideo
        isVideoReady = true 
    }else{
        // video not available
        isVideoReady = false 
    }
})

gamee.showRewardedVideo

Function used to show rewarded ads inside the games, you should load the video first using gamee.loadRewardedVideo.

*Requires declared capability "rewardedAds" during gamee.Init

Complete Usage

if(isVideoReady){
    gamee.showRewardedVideo(function(error,data){
	if(data && data.videoPlayed){
            //video played => user should get reward
	}else{
	   //video not played / skipped => user should not get reward
	}
    })
}

gamee.purchaseItem

Function used to purchase items inside the game using GAMEE Coins.

Parameters

  • coinCost -number- The cost of the item.
  • itemName -string- The name of the item.
  • itemImage -base64Image- The image of the item.
  • developerPayload -json- (Optional) Data to store about the purchase.

*Requires declared capability "coins" during gamee.Init

Complete Usage

gamee.purchaseItem({coinsCost:50,itemName:'ball',
itemImage:dataURL, developerPayload:"Good Item"},function(error,data){
                
    if(data && data.purchaseStatus){ // data.purchaseStatus indicates if the player bought the item or not
        console.log('item bought')
    }else{
        console.log('item not bought')
    }
    if(data.coinsLeft){ // data.coinsLeft indicates remaining amount of coins of player
        var coinsLeft = data.coinsLeft
    }
})

gamee.gameOver

In addition, gameOver can send data that could be used later to run the game in the replay mode or in the ghost mode. Same data are used for both modes, to reflex that it is possible to pass also saveState.

Parameters

  • replayData -json- (Optional) Data to use on replay mode or ghost mode.

Complete usage

var replayData = {
    // your data here, can be stringified json for example
    data: JSON.stringify({"life":50,"level":10}),
    // optional property, useful for games with random levels, should contain seed
    variant: "0.58366025891155"
};

gamee.gameOver(replayData, function(error) {
    if(error !== null)
        throw error;
});

You can also add saveState to the function, so you may stop using gamee.gameSave() and just make one call to the server

Parameters

  • saveState -string- (Optional) Data to use in the game.

Complete Usage

var saveState = JSON.stringify({"score":1000})

gamee.gameOver(null, null, saveState)

gamee.share

Function used to share a post on feed or battles, when another user opens a game from that post the developer will get the shared initData during gamee.gameInit() .

Parameters

  • score -number- (Optional) The score of the Player.
  • text -string- The message for the post.
  • picture -base64Image- Image for the post. The image should be in format 4:3 (640x480px), 1:1 (640x640), or 3:4 (640x852). Maximum size is 150 kB.
  • destination -string- It can be 'feed' or 'battle', it will indicate whrere the post is going to be published.
  • initData -json- (Optional) Data saved it to use it on the post for other players.

*Requires declared capability "share" during gamee.Init

Complete usage

gamee.share({score:1000, text:"Look my Score",picture:base64, 
destination:"feed", initData:json},function(error,data){
    if(data && data.shareStatus){
        console.log("shared post successfully")
    }else{
        console.log("shared post failed")
    }
}

gamee.emitter

Some events like "start" comes with params. In addition this object emits also other events: "ghostHide" and "ghostShow".

Complete usage

// Will be emitted when user will start game or restart it. 
gamee.emitter.addEventListener("start", function(event) {
    ... // your code to start
    event.detail.opt_replay // if true, game must start as replay
    event.detail.opt_ghostMode // if true, game must start in ghostMode 
                               // (unless replay is true)
    event.detail.opt_resetState // if true, game should toss its current saveState
    event.detail.replayData // contains the replayData of the player´s next friend
                            // to beat.

    event.detail.callback();
}); 

gamee.emitter.addEventListener("ghostHide", function(event) {
    ... // your code to hide anything related to ghost in game. 

    event.detail.callback();
});

gamee.emitter.addEventListener("ghostShow", function(event) {
    ... // your code to show anything related to ghost in game again.

    event.detail.callback();
});


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.