玩家观看打赏视频后如何给玩家金币?

How to give the player coins after he or she watches the reward video?

我正在使用 Chartboost 奖励视频,我无法弄清楚如何在视频播放完毕后给玩家 100 个硬币。这是奖励视频的代码。现在即使我退出奖励视频屏幕,它也会添加 100 个硬币。玩家看完视频后如何给金币?

    func loadRewardedVideo() {

    let kChartboostAppID = "appID"
    let kChartboostAppSignature = "appSigniture"

    Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: viewController)

    Chartboost.showRewardedVideo(CBLocationMainMenu)
    Chartboost.cacheRewardedVideo(CBLocationMainMenu)

    if Chartboost.hasRewardedVideo(CBLocationMainMenu) {
        Chartboost.showRewardedVideo(CBLocationMainMenu)

        coins += 200
        totalCoinLabel.text = String(coins)


    }

}

您可以添加一些从奖励视频开始的计时器。 如果用户 returns 到菜单(或关闭 window),计时器停止。

因此,如果计时器未达到 0 秒或 30 秒(无论您的视频时间是多少),玩家就不会获得金币。

我个人没有使用 的经验。但是,基于阅读他们的文档,您需要设置一个委托:

Chartboost.startWithAppId(
    "YOUR_CHARTBOOST_APP_ID",
    appSignature: "YOUR_CHARTBOOST_APP_SIGNATURE",
    delegate: self
)

然后,您的委托可以实现此方法以了解用户何时完全观看了奖励视频:

func didCompleteRewardedVideo(location: CBLocation, withReward reward: Int)

在响应中意外发现 nil,如果您使用的是 spritekit,则必须设置通知以查看控制器,因为如果它找不到您的硬币的价值,它将是 nil