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.

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.'BonusCoins', pauseGame, resumeGame, skipBonus, addBonusCoins);

// This example shows the game flow depending on the outcome of the ad.'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 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.
    image: 'data:base64image',
    text: 'Invite text',
    caption: 'Play',
    data: { exampleData: 'yourData' },

// Share your game activity with friends.
    image: 'data:base64image',
    text: 'Share text',
    caption: 'Play',
    data: { exampleData: 'yourData' },
}).then(result => console.log(result); // Contains shareCount with number of friends the share was sent to.

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

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);