Skip to content

Module: ads

Table of contents

Functions

Functions

isAdBlocked

isAdBlocked(): boolean

Returns whether ads are blocked for the current session. This can be used to determine if an alternative flow should be used instead of showing ads, or prompt the player to disable the ad blocker.

Example

if (Wortal.ads.isAdBlocked()) {
   // Show a message to the player to disable their ad blocker.
   // Or use an alternative flow that doesn't require ads - social invites for rewards as an example.
}

Returns

boolean

True if ads are blocked for the current session. False if ads are not blocked.


showBanner

showBanner(shouldShow?, position?): void

Shows a banner ad. These are small ads that are shown at the top or bottom of the screen. They are typically used on menus or other non-gameplay screens. They can be shown or hidden at any time.

Parameters

Name Type Description
shouldShow boolean Whether the banner should be shown or hidden. Default is show.
position BannerPosition Where the banner should be shown. Top or bottom of the screen. Default is the bottom.

Returns

void


showInterstitial

showInterstitial(placement, description, beforeAd, afterAd, noFill?): void

Shows an interstitial ad. These can be shown at various points in the game such as a level end, restart or a timed interval in games with longer levels.

Example

// Player reached the next level.
Wortal.ads.showInterstitial('next', 'NextLevel', pauseGame, resumeGame);

// Player paused the game.
Wortal.ads.showInterstitial('pause', 'PausedGame', pauseGame, resumeGame);

// Player opened the IAP shop.
Wortal.ads.showInterstitial('browse', 'BrowseShop', pauseAudio, resumeAudio);

Parameters

Name Type Description
placement PlacementType Placement type for the ad.
description string Description of the placement.
beforeAd () => void Callback for before the ad is shown. Pause the game here.
afterAd () => void Callback for after the ad is shown. Resume the game here.
noFill? () => void Callback for when the ad is not filled. This can happen if the platform has no ads to show or if the rate limit has been reached. If this is not provided, the afterAd callback will be used.

Returns

void

Throws

  • INVALID_PARAM

showRewarded

showRewarded(description, beforeAd, afterAd, adDismissed, adViewed, noFill?): void

Shows a rewarded ad. 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.

Example

// 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.
Wortal.ads.showRewarded('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.
Wortal.ads.showRewarded('ReviveAndContinue', pauseAudio, resumeAudio, endGame, continueGame);

Parameters

Name Type Description
description string Description of the placement.
beforeAd () => void Callback for before the ad is shown. Pause the game here.
afterAd () => void Callback for after the ad is shown. Resume the game here.
adDismissed () => void Callback for when the player dismissed the ad. Do not reward the player.
adViewed () => void Callback for when the player has successfully watched the ad. Reward the player here.
noFill? () => void Callback for when the ad is not filled. This can happen if the platform has no ads to show or if the rate limit has been reached. If this is not provided, the afterAd callback will be used.

Returns

void

Throws

  • INVALID_PARAM