Skip to content

Wortal SDK for Cocos Creator 2.x



To use the Wortal SDK in your game, you must build with the web-mobile template. This is included in the extension and handles all the necessary setup.


  1. Call wortal.initializeAsync() as early as possible in your game's initialization code, then wortal.startGameAsync() when your game has finished loading and is ready for play.

  2. Report the loading progress of the game in your initialization code. The game will not start until the loading progress reaches 100%.

wortal.initializeAsync().then(() => {
    // SDK is ready to use.
    // Wait for game to finish loading.

How to Use


API Reference

Interstitial ads can be shown at various points in the game such as a level end, restart or a timed interval in games with longer levels.

// Player reached the next level.'next', 'NextLevel', pauseGame, resumeGame);

// Player paused the game.'pause', 'PausedGame', pauseGame, resumeGame);

// Player opened the IAP shop.'browse', 'BrowseShop', pauseAudio, resumeAudio);

Rewarded ads can be shown too. These are longer, optional ads that the player can earn a reward for watching. The player must be notified of the ad and give permission to show before it can be shown.

// This example shows the game flow independent of the outcome of the ad.
// Ex: Player gets bonus coins for watching the ad, but the game continues regardless of the outcome.'BonusCoins', pauseGame, resumeGame, skipBonus, addBonusCoins);

// This example shows the game flow depending on the outcome of the ad.
// Ex: Player dies and can revive by watching an ad, but if they skip the ad they lose the level.'ReviveAndContinue', pauseAudio, resumeAudio, endGame, continueGame);

NOTE: Players should only be rewarded in the adViewed callback.


API Reference

The Analytics API can be used to track game events that can help better understand how players are interacting with the game. This data will be available for viewing in the Wortal dashboard.

// Logs the start of the level.'Level 3');

// Logs the end of the level. Will track the time spent playing the level if the name matches
// the name of the last logLevelStart() call.'Level 3', '100', true);

// Logs a choice the player made in the game. This can be useful for balancing the game
// and seeing what content your players interact with the most.'Character', 'Blue');


API Reference

The Achievements API is used to track the player's progress in the game and reward them for completing tasks.

// Unlock an achievement.
    .then(() => console.log("Achievement unlocked!"));

// Get the player's achievements progress.
    .then(achievements => console.log(achievements));


API Reference

The Context API is used to connect players and allow them to interact in the game session, share their content and send messages to each other.

// Invite a friend to play the game. Does not switch the player's current context.
    image: 'data:base64Image',
    text: 'Invite text',
    cta: 'Play',
    data: { exampleData: 'yourData' },
}).then(() => console.log("Invite sent!"))

// Share your game activity with friends.
    image: 'data:base64image',
    text: 'Share text',
    cta: 'Play',
    data: { exampleData: 'yourData' },
}).then(result => console.log(result));

In-App Purchases

API Reference

The In-App Purchases (IAP) API is used to provide an interface for in-game transactions on the platforms. This process will differ based on what platform the game is being played on, but the API remains the same.

// Get the catalog of products the player can purchase.
    .then(products => console.log(products));

// Purchase a product.
    productID: 'my_product_123',
}).then(purchase => console.log(purchase));


API Reference

The Leaderboard API gives the game access to the platform's leaderboard functionality. This is where you can track player's scores and compare them to other players.

// Get the top 10 entries on the global leaderboard.
wortal.leaderboard.getEntriesAsync('global', 10)
    .then(entries => console.log(entries));

// Add the player's score to the leaderboard.
wortal.leaderboard.sendEntryAsync('global', 100);


API Reference

The Notifications API is used to send notifications to the player. These can be used to notify the player of an event in the game or to remind them to come back and play.

// Schedule a notification to send to the player.
    title: "Your energy is full!",
    body: "Come back and play again.",
    mediaURL: "",
    label: "resources-full",
    scheduleInterval: 300 // 5 minutes
}).then((result) => {

// Cancel a scheduled notification.
    .then((result) => {


API Reference

You can find details about the current player via the Player API.

// Get the player's name.

// Get a list of the player's friends who have also played this game.
    filter: 'ALL',
    size: 20,
    hoursSinceInvitation: 4,
}).then(players => console.log(players.length));


API Reference

Details about the current session can be accessed in the Session API.

// Get the entry point of where the game started from.
    .then(entryPoint => console.log(entryPoint));

// Get the entry point data from a social invite or share.
// This is useful for tracking where players are coming from or
// providing a reward for players who were invited to play.
const data = wortal.session.getEntryPointData();


API Reference

Track stats for players and record their high scores with the Stats API.

// Get the player's high score for the level.
    .then(stats => console.log(stats.value));

// Set the player's high score for the game.
wortal.stats.postStatsAsync("level1", 1000)
    .then(() => console.log("High score set!"));


API Reference

The Tournament API is used to create and manage tournaments for your game.

// Create a tournament.
const payload = {
    initialScore: 100,
    config: {
        title: "Level 1 Tournament",
    data: {
        level: 1,

    .then(tournament => console.log(tournament.payload["level"]));

// Post a score to a tournament.
    .then(() => console.log("Score posted!"));