JavaScript

The JavaScript version of the API allows you to extend your game developed in JavaScript to comunicate with the back­-end of Click Jogos.

Getting Started
Specific Documentation
Download Game Sample Code

Getting Started

This is a step-by-step guide how to integrate the Click Jogos API in your game.

The working of the JavaScript version of the API is very similar to AS3 version, but it is not necessary to instantiate the API, the default class 'CJAPI' is already instantiated and available.

Download the api.js

Each API function triggers events that need to be listened to obtain and use data from back-end of Click Jogos. In JavaScript version this is done through the bind(), that listens the data arrival, and distributes for any given function.

Read more and the sampler code

After adding all of event listener for the functions that you intent to use, you are able to call them. Remember that the API's functions are separeted into packeges to take the manipulatyion more easy.

See all of the API's functions

Now you can send any event in your game to Click Jogos, so you need to create the stats and the achievements that will be delivered for users.

See how to create and submmit Stats See how to create Achievements

The submission process for games is very easy and simple, after insert the game name, the description, create stats and achievements, you just need to select the file of your game, insert the width and heigth of the frame, read and accept the terms of licence of the API, and submit.

Submit_en

After upload your game with success you will see a button where is possible take a preview of your game and test sending of stats and the delivering of achievements. This button can also be seen in the edition of your game.

Congrats_en

Loading the API

When your game is within our sandbox, the JavaScript version is already loaded automatically, so it is not necessary to include any file in your game. The JavaScript version of the API allows to instantiating the API, use its functions and send actions in a simple and straightforward way.

The working of the JavaScript version of the API is very similar to AS3 version, but it is not necessary to instantiate the API, the default class 'CJAPI' is already instantiated and available.

Salt Parameter

You must to generate the salt parameter in all of function that will do requests in our server

All of your game’s requests to our server must send the salt parameter along with it, and this need to be enconded in base64 and generated in all request.

Event Listeners

Each API function triggers events that need to be listened to obtain and use data from back-end of Click Jogos. In JavaScript version this is done through the bind(), that listens the data arrival, and distributes for any given function.

Event Listeners Code Examples

There is two kinds of event listeners for each function of our API, success event listeners and error event listeners.

Users Stats Services

The event onGetUsername() returns ‘Guest’ if the current user is not logged in, or if the user is logged its return 'Username logged'. The event onGetUsernameErrors() returns false for success and an array containing the errors.

The event onSubmitStat() returns true for success, if there is an achievement to be released is returned its name, the stat type and current value of the stat. The event onSubmitStatError() returns false for success and an array containing the errors.

The event onIsSignedIn() returns ‘Guest’ if the current user is not logged in, or if the user is logged its return 'Username logged'. The event onIsSignedInError() returns false for success and an array containing the errors.