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:
- JavaScript
- Construct 3
- Unity
// Current language, format ISO 639-1
gp.language
// Current language, format ISO 639-1
GS_Language.Current();
To set language:
- JavaScript
- Construct 3
- Unity
// set language, format ISO 639-1 ('ru', 'en', 'fr')
gp.changeLanguage('ru')
// Формат ISO 639-1 ('ru', 'en', 'fr')
GS_Language.Change(Language.ru);
All supported languages:
- English:
en
- Russian:
ru
- French:
fr
- Italian:
it
- German:
de
- Spanish:
es
- Chineese (Simplified):
zh
- Portuguese (Brazil):
pt
- Korean:
ko
- Japanese:
ja
- Turkish:
tr
- Arab:
ar
- Hindi:
hi
- Indonesian:
id
System Information
Device detection:
- JavaScript
- Construct 3
- Unity
/**
* Mobile / desktop device
* @readonly
* @type {boolean}
*/
gp.isMobile
/**
* Мобильное / десктопное устройство
* @readonly
* @type {boolean}
*/
GS_Device.IsMobile();
Game Host Information:
- 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 в режиме разработки
* За это отвечает галка dev у нужного источника
* @readonly
* @type {boolean}
*/
GS_System.IsDev();
/**
* Хост игры в доверенных источниках
* За это отвечает раздел Allowed Origins
* @readonly
* @type {boolean}
*/
GS_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
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:
- 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());
}
// Текущее серверное время в формате ISO 8601
GS_Server.Time();
// Пример использования
DateTime dt = GS_Server.Time();
if (dt > lastDate)
{
GS_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:
- JavaScript
- Construct 3
- Unity
/**
* Is on pause
* @readonly
* @type {boolean}
*/
gp.isPaused
/**
* На паузе
* @readonly
* @type {boolean}
*/
GS_Game.IsPaused();
Set pause manually:
- JavaScript
- Construct 3
- Unity
// Pause game
gp.pause();
// Resume game
gp.resume();
// Поставить на паузу
GS_Game.Pause();
// Возобновить
GS_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()
{
GS_Game.OnPause += Pause;
}
private void Pause()
{
Debug.Log("is Pause");
}
Set background image
You 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
Game 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
In Unity is called automatically
Gameplay
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.
- JavaScript
- Construct 3
- Unity
// Notify when gameplay starts
gp.gameplayStart();
// Notify when finished
gp.gameplayStop();
Not implemented in Unity yet.
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!