我怎样才能将一则插播广告整合到swift 3中。这是一个虚拟按钮 我怎样才能将一则插播广告整合到swift 3中。这是一个虚拟按钮。这是我的暂停屏幕的样子:导入SpriteKit
让按钮_距离:CGFloat=15 让背景颜色=UIColor(红色:255,绿色:255,蓝色:255,阿尔法:0.2) 类暂停{ 让我们继续按钮:按钮 让我们重置按钮:按钮 让菜单按钮:按钮 让root:SKNode=SKNode() 让gameDelegate:gameDelegate let背景:SKSpriteNode我怎样才能将一则插播广告整合到swift 3中。这是一个虚拟按钮 我怎样才能将一则插播广告整合到swift 3中。这是一个虚拟按钮。这是我的暂停屏幕的样子:导入SpriteKit,swift,xcode,swift3,admob,google-admob,Swift,Xcode,Swift3,Admob,Google Admob,让按钮_距离:CGFloat=15 让背景颜色=UIColor(红色:255,绿色:255,蓝色:255,阿尔法:0.2) 类暂停{ 让我们继续按钮:按钮 让我们重置按钮:按钮 让菜单按钮:按钮 让root:SKNode=SKNode() 让gameDelegate:gameDelegate let背景:SKSpriteNode init(scene: SKScene, delegate: GameDelegate) { self.gameDelegate = delegate
init(scene: SKScene, delegate: GameDelegate) {
self.gameDelegate = delegate
root.position = CGPoint(x: scene.frame.midX, y: scene.frame.midY)
root.zPosition = 5
resumeButton = Button(scene: scene, parent: root, text: "Resume",
x: 0, y: DEFAULT_BUTTON_SIZE.height + BUTTON_DISTANCE,
action: gameDelegate.gameResumed)
resetButton = Button(scene: scene, parent: root, text: "Reset",
x: 0, y: 0, action: gameDelegate.gameReseted)
menuButton = Button(scene: scene, parent: root, text: "Menu",
x: 0, y: -(DEFAULT_BUTTON_SIZE.height + BUTTON_DISTANCE),
action: gameDelegate.returnMenu)
background = SKSpriteNode()
background.size = scene.size
background.position = CGPoint(x: 0, y: 0)
background.color = BACKGROUND_COLOR
root.addChild(background)
hide()
scene.addChild(root)
}
func touch(_ touch: UITouch) {
resumeButton.press(touch)
resetButton.press(touch)
menuButton.press(touch)
}
func release(_ touch: UITouch) {
resumeButton.release(touch)
resetButton.release(touch)
menuButton.release(touch)
}
func hide() {
root.isHidden = true
}
func show() {
root.isHidden = false
}
}
我希望在单击rest按钮时显示广告-Thx Zain因此,每当按下某个场景中的按钮时,您要做的就是从
GameViewController
运行一个函数(显示广告)。为此,您需要执行以下操作:
在GameViewController中,在viewWillLayoutSubviews
中设置通知观察者,并设置显示广告的功能:
override func viewWillLayoutSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)
}
func showAd() {
//Code to show the interstitial ad
}
然后在场景中,当您希望运行GameViewController
中的函数时,调用此函数:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)
当按下按钮时,您将在场景中运行此代码 因此,只要按下其中一个场景中的按钮,您就可以从
GameViewController
运行一个函数(显示广告)。为此,您需要执行以下操作:
在GameViewController中,在viewWillLayoutSubviews
中设置通知观察者,并设置显示广告的功能:
override func viewWillLayoutSubviews() {
NotificationCenter.default.addObserver(self, selector: #selector(self.showAd), name: NSNotification.Name(rawValue: "showAd"), object: nil)
}
func showAd() {
//Code to show the interstitial ad
}
然后在场景中,当您希望运行GameViewController
中的函数时,调用此函数:
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "showAd"), object: nil)
当按下按钮时,您将在场景中运行此代码 你能澄清一下你的要求吗?我想在有人点击“重置按钮”时播放插播广告看看这个:如果你愿意,我可以给你一个具体的答案want@Nik我是swift的新手,你能告诉我如何使用重置按钮吗?你能澄清你的要求吗?我想在有人点击“重置按钮”时播放插播广告看看这个:如果你愿意,我可以给你一个具体的答案want@Nik我是新来的斯威夫特,你能告诉我怎么重置吗button@user6794475你能补充这个问题还是打开一个新的问题。错误消息是什么?我建议你从评论中删除你的电子邮件。这不是一封真正的电子邮件,如果你可以的话,我为你写的help@user6794475我不会给你编码的。我将为您提供您自己需要做的事情,如果您有任何后续问题/疑问/顾虑,您可以添加到question@user6794475你能补充这个问题还是打开一个新的问题。错误消息是什么?我建议你从评论中删除你的电子邮件。这不是一封真正的电子邮件,如果你可以的话,我为你写的help@user6794475我不会给你编码的。我为您提供了自己需要做的事情,如果您有任何后续问题,您可以添加到您的问题中