gpt4 book ai didi

ios - 游戏中心 "Done"按钮问题?

转载 作者:搜寻专家 更新时间:2023-11-01 07:27:17 26 4
gpt4 key购买 nike

Game Center 中的“完成”按钮不会关闭 Controller 。我关闭 View Controller 的代码在任何地方都完全相同。我在这里看过类似的问题,但没有运气。谁能帮帮我?

GameScene.Swift(这是我的开始菜单)

class GameScene: SKScene, GKGameCenterControllerDelegate {


var startBtn = SKSpriteNode(imageNamed: "play button")
var title = SKLabelNode(fontNamed: "AvenirNext-UltraLight")
var leaderboardButtonImage = SKSpriteNode(imageNamed: "leaderboard button")

override func didMoveToView(view: SKView) {

let bounds = UIScreen.mainScreen().bounds
self.scene?.size = CGSize(width: bounds.size.width, height: bounds.size.height)

scene?.backgroundColor = UIColor.whiteColor()

startBtn.position = CGPoint(x: self.frame.width / 2 - 100, y: self.frame.height / 2)
startBtn.size = CGSize(width: 140, height: 55)
self.addChild(startBtn)

leaderboardButtonImage.position = CGPoint(x: self.frame.width / 2 + 100, y: self.frame.height / 2)
leaderboardButtonImage.size = CGSize(width: 140, height: 55)
self.addChild(leaderboardButtonImage)

}





func showLeaderboard() {

let vc = self.view?.window?.rootViewController
let gc = GKGameCenterViewController()

gc.viewState = GKGameCenterViewControllerState.Leaderboards
gc.leaderboardIdentifier = "I removed this part"
vc!.presentViewController(gc, animated: true, completion: nil)



}

func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) {

gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)


}




override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */

for touch in (touches ) {
let location = touch.locationInNode(self)

if (startBtn.containsPoint(location)) {

self.view?.presentScene(GamePlayScene(), transition: SKTransition.crossFadeWithDuration(1.0))
GamePlayScene().scaleMode = .ResizeFill
startBtn.removeFromParent()
title.removeFromParent()
leaderboardButtonImage.removeFromParent()

}

if (leaderboardButtonImage.containsPoint(location)) {

showLeaderboard()

}

}

}



}

最佳答案

在我的 func showLeaderboard() 中,我必须添加 gc.gameCenterDelegate = self 这行,这使得“完成”按钮起作用。

我希望遇到同样问题的其他人看到这个潜在的修复方法。

func showLeaderboard() {

let vc = self.view?.window?.rootViewController
let gc = GKGameCenterViewController()

gc.viewState = GKGameCenterViewControllerState.Leaderboards
gc.gameCenterDelegate = self
gc.leaderboardIdentifier = "I removed this part"
vc!.presentViewController(gc, animated: true, completion: nil)

}

关于ios - 游戏中心 "Done"按钮问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35165282/

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