Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions pixijs/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,47 @@ async function main() {
backgroundColor: 0x23272a,
});

// Example of loading an imported asset.
const cube = new Sprite(assetManager.load("/assets/sprites/cube.png"));
cube.eventMode = 'static';
cube.on('pointerup', (_) => {
ytgame.ads.requestInterstitialAd();
// Example of loading imported assets for ad test buttons.
const interstitialCube = new Sprite(assetManager.load("/assets/sprites/cube.png"));
interstitialCube.x = 0;
interstitialCube.eventMode = 'static';
interstitialCube.on('pointerup', async () => {
await requestInterstitialAd();
});
app.stage.addChild(cube);
app.stage.addChild(interstitialCube);

const rewardedCube = new Sprite(assetManager.load("/assets/sprites/cube.png"));
rewardedCube.x = 150;
rewardedCube.eventMode = 'static';
rewardedCube.on('pointerup', async () => {
await requestRewardedAd();
});
app.stage.addChild(rewardedCube);

// Do other setup work here, if needed. Then,
// tell the SDK that the game is ready to be played.
ytgame.game.gameReady();

async function requestInterstitialAd() {
try {
await ytgame.ads.requestInterstitialAd();
console.debug("Interstitial ad requested successfully.");
} catch (error) {
console.warn("Failed to request interstitial ad:", error);
}
}

async function requestRewardedAd() {
try {
const isRewardEarned = await ytgame.ads.requestRewardedAd(
"21403813-2e22-4316-a8b2-7d4f52a6f6fb"
);
console.debug(`Reward earned: ${isRewardEarned}`);
} catch (error) {
console.warn("Failed to request rewarded ad:", error);
}
}

// Play music, for fun.
const backgroundSound = assetManager.load("/assets/sounds/moonlight.mp3");
backgroundSound.play();
Expand Down
15 changes: 15 additions & 0 deletions pixijs/src/types/sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ declare namespace ytgame.ads {
*/
export function requestInterstitialAd(): Promise<void>;

/**
* Requests a rewarded ad to be shown.
* @experimental
*
* 🧪 PUBLIC PREVIEW API: SUBJECT TO CHANGE WITHOUT NOTICE.
*
* This request may resolve successfully even if an ad is not shown.
* On success the resolved value indicates whether the player earned the reward.
*
* @param rewardId - A unique identifier for the reward being offered.
* @returns A promise that resolves with `true` when the player earned the reward and `false` otherwise.
* @throws `ytgame.SdkError`
*/
export function requestRewardedAd(rewardId: string): Promise<boolean>;

/**
* The possible outcomes of a successful ad break.
* @hidden
Expand Down