Skip to main content

Common Features

Language

SDK can autodetect players language. If the platform provides a language, we use it or pick player-preferred language.

To check language FREE:

// Current language, format ISO 639-1
gp.language;

To set language FREE:

// set language, format ISO 639-1 ('ru', 'en', 'fr')
gp.changeLanguage("ru");

All supported languages:

  • English: en
  • French: fr
  • Italian: it
  • German: de
  • Spanish: es
  • Chinese (Simplified): zh
  • Portuguese (Brazil): pt
  • Korean: ko
  • Japanese: ja
  • Russian: ru
  • Turkish: tr
  • Arab: ar
  • Hindi: hi
  • Indonesian: id

System Information

Device detection

FREE
/**
* Mobile / desktop device
* @readonly
* @type {boolean}
*/
gp.isMobile;

Screen mode: portrait / landscape

FREE
/**
* Portrait / landscape screen mode
* @readonly
* @type {boolean}
*/
gp.isPortrait;

Subscribe to change orientation event:

gp.on("change:orientation", (isPortrait) => {
logger.log("orientation changed", { isPortrait });
});

Game Host Information

FREE
/**
* GamePush in development mode
* The checkbox dev at the desired source is responsible for this
* @readonly
* @type {boolean}
*/
gp.isDev;

/**
* Game host in trusted sources
* The Allowed Origins section is responsible for this.
* @readonly
* @type {boolean}
*/
gp.isAllowedOrigin;

You can use the gp.isAllowedOrigin property to check whether the game has been re-uploaded to another site. In the Allowed Origins section there is a switch - Enable origin protection. It will block all new unknown game hosts. In the list of hosts, you can allow access to the desired hosts.

Server Time

FREE

The SDK provides access to server time.

It is always valid, it cannot be changed through the code and by changing the time of the device. You can use it as a reliable time to protect against cheating.

To get time FREE:

// Read-only current server time in ISO 8601 format
gp.serverTime;

// Example of using
// One hour in milliseconds
const HOUR = 60 * 60 * 1000;
// Current time
const currentDate = new Date(gp.serverTime);
// Previous reward time
const lastDate = new Date(
gp.player.get("lastRewardTime") || currentDate - HOUR
);

// If an hour of playing time has passed, we give a reward
// And update the time of last reward
if (currentDate - lastDate > HOUR) {
gp.player.add("gold", 5000);
gp.player.set("lastRewardTime", currentDate.toISOString());
}

Pause

You have access to the pause control mechanism in the game. The SDK has a "Paused" flag, by itself it means nothing, however, you can engage in it if you need to pause and continue the game. Additionally, the SDK will notify you when a pause or resume has been triggered.

Auto pause occurs when:

  • Show ads. Pause at the beginning of the show and resume at the close (not when receiving an award).
  • Minimize game. Pause when switching tabs, minimizing the browser, switching applications, locking the screen, and resuming when the game is visible again.

Pause definition FREE:

/**
* Is on pause
* @readonly
* @type {boolean}
*/
gp.isPaused;

Set pause manually FREE:

// Pause game
gp.pause();
// Resume game
gp.resume();

Pause and resume events:

// Paused
gp.on("pause", () => {});
// Resumed
gp.on("resume", () => {});

Set background image

FREE

You can set the background of the game.

Background set method:

gp.setBackground({ url: "/bg.png" });

Full features of the method:

gp.setBackground({
// Image link
url: "/bg.png",
// Background image blur, px
blur: 10,
// Duration of image change animation, sec
fade: 5,
});

You can call the method one by one to change the background image, for example:

// Set background
gp.setBackground({ url: "/bg.png", blur: 10, fade: 5 });
// Change to another
gp.setBackground({ url: "/bg2.png", blur: 6, fade: 12 });

Start game

FREE

Game start method, required by some sites to set at the start of the game

The call should depend after the game is loaded:
gp.gameStart();

Gameplay

FREE

For some platforms, such as POKI and CrazyGames, you need to call the start and end gameplay methods. They need to be called immediately before the start of the gameplay and immediately after completion. For example, at the beginning of the level and the end of the level.

// Notify when gameplay starts
gp.gameplayStart();

// Notify when finished
gp.gameplayStop();

Stay in Touch

Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.

GamePush Community Telegram: @gs_community.

For your suggestions e-mail: [email protected]

We Wish you Success!

```