gpt4 book ai didi

swift - 我如何将承认插页式广告集成到 swift 3 中。它是一个虚拟按钮

转载 作者:行者123 更新时间:2023-11-28 08:18:54 26 4
gpt4 key购买 nike

code of my pause menu我如何将承认插页式广告集成到 swift 3 中。它是一个虚拟按钮。这是我的暂停屏幕的样子:import SpriteKit

让 BUTTON_DISTANCE: CGFloat = 15let BACKGROUND_COLOR = UIColor(red: 255, green: 255, blue: 255, alpha: 0.2)

类暂停菜单{ 让resumeButton:按钮 让 resetButton: 按钮 让菜单按钮:按钮 让根:SKNode = SKNode() 让 gameDelegate: GameDelegate 让背景:SKSpriteNode

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
}

我希望在您点击休息按钮时显示广告。 -谢谢扎因

最佳答案

因此,您要做的是在您的某个场景中的某个按钮被按下时,从您的 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)

您可以将这段代码放在场景中,以便在按下按钮时运行。

关于swift - 我如何将承认插页式广告集成到 swift 3 中。它是一个虚拟按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41797288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com