Ads
AI Summary
A short gist of this page, generated for you.
Powered by AI. Summaries can miss nuance — when in doubt, read the page.
The SDK shows two kinds of ads:
- Interstitial — shown at natural breakpoints with
commercialBreak() - Rewarded — started by the player in exchange for a reward, with
rewardedBreak()
On the Funox website the ad opens over your game's frame; in the Funox mobile app the app shows it. Your code is the same in both.
Before shipping ads, read the advertisement requirements.
#Rules for every ad call
- Pause and mute your game yourself before the call, and resume when the promise settles. Do not wait for a
pauseevent to do it. - One ad at a time. A call made while an ad is open resolves right away with
reason: 'already_showing'. - An ad is not always available. The SDK waits up to 5 seconds for one, then resolves with
shown: false. Continue the game either way. - Do not retry in a loop. After a failed request the SDK asks for a new ad at most once every 10 seconds.
- Ads may not be available while you test locally.
#commercialBreak()
Requests an interstitial ad. Call it at natural break points: between levels, after death, when a menu opens.
commercialBreak() is one of the four required calls.
function onLevelComplete() {
pauseGameAudio();
pauseGameLoop();
FunOxSDK.commercialBreak()
.then(function (result) {
// result.shown — was an ad displayed?
// result.completed — did it finish?
})
.catch(function () { /* treat a failure like "no ad shown" */ })
.then(function () {
resumeGameAudio();
resumeGameLoop();
loadNextLevel();
});
}#Result
{
"shown": true,
"completed": true
}When no ad was shown, the result says why:
{
"shown": false,
"completed": false,
"reason": "no_fill"
}#rewardedBreak()
Requests a rewarded video ad. Pass a name for the reward. Each call shows one ad, and you must use result.completed to decide whether to grant the reward.
function onPlayerClicksExtraLife() {
pauseGameAudio();
pauseGameLoop();
FunOxSDK.rewardedBreak('extra_life')
.then(function (result) {
if (result.completed) {
grantExtraLife(); // the player watched the whole ad
} else {
showMessage('Watch the full ad to get your reward!');
}
})
.catch(function () { /* no reward */ })
.then(function () {
resumeGameAudio();
resumeGameLoop();
});
}#Result
{
"shown": true,
"completed": true,
"reward": { "type": "extra_life", "amount": 1 }
}reward is null when the reward was not earned, and reason says why.
#isRewardedAdAvailable()
Resolves with true when a rewarded ad is ready. Use it to decide whether to show the reward button.
FunOxSDK.isRewardedAdAvailable().then(function (available) {
rewardButton.visible = available;
});#Reasons
When shown or completed is false, reason is one of:
reason |
Meaning |
|---|---|
already_showing |
Another ad is still open |
not_ready |
No ad became ready in time |
no_fill |
No ad was available for this request |
user_closed |
Rewarded ads only: the player closed the ad before earning the reward |
error |
The ad failed to display |
standalone_mode |
Standalone mode with in-frame ads turned off |
These are normal results, not errors: the promise resolves. Your game must carry on in every case.
#End-to-end example
function onPlayerDeath() {
FunOxSDK.gameplayStop();
// Offer a rewarded "extra life" first, if one is ready
FunOxSDK.isRewardedAdAvailable().then(function (available) {
if (available && canOfferRevive()) {
showReviveButton(); // calls onPlayerClicksExtraLife() when pressed
return;
}
// Otherwise show an interstitial before the retry screen
pauseGame();
FunOxSDK.commercialBreak()
.catch(function () {})
.then(function () {
resumeGame();
showRetryScreen();
});
});
}