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
ss.language;

To set language FREE:

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

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}
*/
ss.isMobile;

Screen mode: portrait / landscape

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

Subscribe to change orientation event:

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

Game Host Information

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

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

You can use the ss.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
ss.serverTime;

// Example of using
// One hour in milliseconds
const HOUR = 60 * 60 * 1000;
// Current time
const currentDate = new Date(ss.serverTime);
// Previous reward time
const lastDate = new Date(ss.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) {
ss.player.add('gold', 5000);
ss.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}
*/
ss.isPaused;

Set pause manually FREE:

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

Pause and resume events:

// Paused
ss.on('pause', () => {});
// Resumed
ss.on('resume', () => {});

Set background image

FREE

You can set the background of the game.

Background set method:

ss.setBackground({ url: '/bg.png' });

Full features of the method:

ss.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
ss.setBackground({ url: '/bg.png', blur: 10, fade: 5 });
// Change to another
ss.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:
ss.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
ss.gameplayStart();

// Notify when finished
ss.gameplayStop();

Stay in Touch

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

SpellSync Community Telegram: @spellsync.

For your suggestions e-mail: [email protected]

We Wish you Success!

```