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:
- JavaScript
- Construct 3
- Unity
// Current language, format ISO 639-1
gp.language;
// Current language, format enum Language ("English", "Russian")
GP_Language.Current();
// Current language, format ISO 639-1
GP_Language.CurrentISO();
To set language FREE:
- JavaScript
- Construct 3
- Unity
// set language, format ISO 639-1 ('ru', 'en', 'fr')
gp.changeLanguage("ru");
// Format enum Language ("English", "Russian")
GP_Language.Change(Language.English);
// Format ISO 639-1 ('ru', 'en', 'fr')
GP_Language.Change("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- JavaScript
- Construct 3
- Unity
/**
* Mobile / desktop device
* @readonly
* @type {boolean}
*/
gp.isMobile;
/**
* Mobile / desktop device
* @readonly
* @type {boolean}
*/
GP_Device.IsMobile();
Screen mode: portrait / landscape
FREE- JavaScript
- Construct 3
- Unity
/**
* Portrait / landscape screen mode
* @readonly
* @type {boolean}
*/
gp.isPortrait;
/**
* Portrait / landscape screen mode
* @readonly
* @type {boolean}
*/
GP_Device.IsPortrait();
Subscribe to change orientation event:
- JavaScript
- Construct 3
- Unity
gp.on("change:orientation", (isPortrait) => {
logger.log("orientation changed", { isPortrait });
});
// Subscribe to an event
private void OnEnable()
{
GP_Device.OnChangeOrientation += OnChangeOrientation;
}
private void OnChangeOrientation()
{
Debug.Log("orientation changed");
}
Game Host Information
FREE- JavaScript
- Construct 3
- Unity
/**
* 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;
Is Dev Mode - GamePush is in development mode. The dev checkbox is responsible for this at the desired site in Allowed Origins.
Is Allowed Origin - Host the game in trusted origins. The Allowed Origins section is responsible for this.
/**
* GamePush in developer mode
* This is the responsibility of the "dev" checkbox at the desired source
* @readonly
* @type {boolean}
*/
GP_System.IsDev();
/**
* The game host is in trusted sources
* "Allowed Origins" is responsible for this
* @readonly
* @type {boolean}
*/
GP_System.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
FREEThe 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:
- JavaScript
- Construct 3
- Unity
// 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());
}
// Current server time in format ISO 8601
GP_Server.Time();
// Usage example
DateTime dt = GP_Server.Time();
if (dt > lastDate)
{
GP_Player.AddScore(250);
}
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:
- JavaScript
- Construct 3
- Unity
/**
* Is on pause
* @readonly
* @type {boolean}
*/
gp.isPaused;
/**
* On pause
* @readonly
* @type {boolean}
*/
GP_Game.IsPaused();
Set pause manually FREE:
- JavaScript
- Construct 3
- Unity
// Pause game
gp.pause();
// Resume game
gp.resume();
GP_Game.Pause();
GP_Game.Resume();
Pause and resume events:
- JavaScript
- Construct 3
- Unity
// Paused
gp.on("pause", () => {});
// Resumed
gp.on("resume", () => {});
// Subscribe to an event
private void OnEnable()
{
GP_Game.OnPause += Pause;
}
private void Pause()
{
Debug.Log("is Pause");
}
Set background image
FREEYou can set the background of the game.
Background set method:
- JavaScript
- Construct 3
- Unity
gp.setBackground({ url: "/bg.png" });
Not implemented in Unity.
Full features of the method:
- JavaScript
- Construct 3
- Unity
gp.setBackground({
// Image link
url: "/bg.png",
// Background image blur, px
blur: 10,
// Duration of image change animation, sec
fade: 5,
});
Not implemented in Unity.
You can call the method one by one to change the background image, for example:
- JavaScript
- Construct 3
- Unity
// Set background
gp.setBackground({ url: "/bg.png", blur: 10, fade: 5 });
// Change to another
gp.setBackground({ url: "/bg2.png", blur: 6, fade: 12 });
Not implemented in Unity.
Start game
FREEGame start method, required by some sites to set at the start of the game
- JavaScript
- Construct 3
- Unity
gp.gameStart();
In Construct 3 is called automatically
GP_Game.GameReady();
You can also call it automatically.
Gameplay
FREEFor 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.
- JavaScript
- Construct 3
- Unity
// Notify when gameplay starts
gp.gameplayStart();
// Notify when finished
gp.gameplayStop();
// Notify when gameplay starts
GP_Game.GameplayStart();
// Notify when finished
GP_Game.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!
```