Swift SpriteKit iAd [英] Swift SpriteKit iAd

查看:76
本文介绍了Swift SpriteKit iAd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Swift开发游戏,但有一个我无法解决的小问题.我只处理场景,没有UIViews.主要场景是游戏运行的地方,当玩家死亡时,将加载一个新场景.我希望在玩家死亡的那个场景中显示菜单(我这样做了)并显示iAd标语.我也尝试过使用UIViewControllers,但是我无法管理它.我只想在SpriteKit中制作它,我不知道怎么做.有人可以帮我吗?

I'm developing a game in Swift and I have a little problem that I couldn't solve. I'm working only with scenes, I have no UIViews. The main scene is where the game runs and when the players dies a new scene will be loaded. I want in that scene, where the player dies, to display a menu (which I did) and to display iAd banners. I tried also with UIViewControllers but I couldn't manage it. I want to make it only in SpriteKit and I don't know how. Could anybody help me please?

推荐答案

如果您只想显示iAd标语,则需要做几件事.首先,导入iAd框架,然后将iAd导入代码的顶部.然后,使用此功能显示横幅. (哦,应该在您的场景中将adBannerView声明为全局变量).

If you simply want to display an iAd banner then you'll need to do several things. First, import the iAd framework and import iAd the the top of your code. Then, use this function to display the banner. (oh, and adBannerView should be declared as a global variables within your skscene).

func loadAds()->ADBannerView{
    adBannerView = ADBannerView(frame: CGRect.zeroRect)
    adBannerView.center = CGPoint(x: adBannerView.center.x, y: view!.frame.size.height - adBannerView.frame.size.height / 2)
    adBannerView.delegate = self
    self.view?.addSubview(adBannerView)
    return adBannerView
}

您可能还希望包括这些功能.当横幅广告无法加载时,此权限就会运行(这很可能是由于网络问题而发生).

You may also want to include these functions. This one right here runs when the banner cannot load (this will most likely occur due to a network problem).

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("Ad cannot load")
    self.adBannerView.hidden = true
}

这将在横幅广告成功加载后运行.

This runs when the banner successfully loads.

func bannerViewDidLoadAd(banner: ADBannerView!) {
    println("ad did load.")
    self.adBannerView.hidden = false
}

这篇关于Swift SpriteKit iAd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆