跳转到内容

广告(Cocos)

两种广告类型:插屏(非自愿、全屏打断)和激励(玩家主动观看,看完拿奖励)。

把 UI 卡住 —— 没有 provider 就绪时,不要露出”看广告”按钮。

if (FRVRSDK.instance.isRewardedReady()) {
  showWatchAdButton();
}

if (FRVRSDK.instance.isInterstitialReady()) {
  // 此时可以尝试展示插屏
}
await FRVRSDK.instance.showInterstitial();

无论广告播出还是被跳过/被节流,promise 都会 resolve。插屏没有独立的”已完成”状态 —— promise 落地就代表广告视图已经结束。

import { AdShowResult } from './frvr-sdk/FRVRSDK';

const result = await FRVRSDK.instance.showRewarded();
if (result === AdShowResult.COMPLETED) {
  giveReward();                 // 看完整支广告 —— 发放奖励
} else if (result === AdShowResult.SKIPPED) {
  // 广告展示了但用户在结束前关闭 —— 不发奖励
} else {
  // AdShowResult.FAILED —— 根本没能展示(无填充/被节流/出错)
}

仅在结果为 COMPLETED 时发放奖励。SKIPPED 表示广告已展示但用户在结束前关闭(不发奖励);FAILED 表示根本没能展示(无填充/被节流/出错)。跳过与失败是两个不同的值,可据此区分用户主动跳过和投放失败。

async onDoubleRewardButtonClicked() {
  this.doubleRewardButton.interactable = false;
  try {
    const result = await FRVRSDK.instance.showRewarded();
    if (result === AdShowResult.COMPLETED) {
      this.currentRunCoins *= 2;
      this.toast('Rewarded!');
    } else if (result === AdShowResult.SKIPPED) {
      this.toast('看完整支广告才能拿奖励');
    } else {
      this.toast('Ad unavailable right now');
    }
  } catch {
    this.toast('Ad unavailable right now');
  } finally {
    this.doubleRewardButton.interactable = true;
  }
}

底层 SDK 会对插屏做节流(冷却约 5 分钟,初始化阻塞约 100 秒)。激励广告不做节流。如果插屏”什么都没发生”,通常是节流器在起作用 —— 不是 bug。

  • 瀑布流、节流参数、Web SDK 暴露但 Cocos 子集没有的广告类型:Web SDK 广告