ios - Swift 3 Game Center 排行榜不保存分数值
<p><p>我有一个问题,请帮助我理解主题。老实说,我花了几天时间研究这个主题,但它还没有工作。</p>
<p>SpriteKit 上有一个简单的游戏,Swift 3。</p>
<p>我正在尝试实现排行榜游戏中心。</p>
<p>iTunes Connect 已设置,排行榜已创建,测试用户已创建。</p>
<p>当我开始游戏时,用户按照他们应该登录的方式登录。显示创建的棋盘的按钮,我可以在 Game Center 中打开我的排行榜。</p>
<p>问题是排行榜中得分的值没有更新。</p>
<p>我的游戏分数存储在变量“score”中
在 gamescene.swift 中,我有两个函数用于保存和覆盖:</p>
<pre><code>func saveHighscore(gameScore: Int) {
if GKLocalPlayer.localPlayer().isAuthenticated {
print("\n Success! Sending highscore of \(score) to leaderboard")
let scoreReporter = GKScore(leaderboardIdentifier: “MY_ID_THERE”)
scoreReporter.value = Int64(gameScore)
let scoreArray: =
GKScore.report(scoreArray, withCompletionHandler: {error -> Void in
if error != nil {
print("An error has occured: \(String(describing: error))")
}
})
}
}
func overrideHighestScore(gameScore: Int) {
UserDefaults.standard.integer(forKey: "highestScore")
if gameScore > UserDefaults.standard.integer(forKey: "highestScore") {
UserDefaults.standard.set(gameScore, forKey: "highestScore")
UserDefaults.standard.synchronize()
saveHighscore(gameScore: score)
print(score.hashValue)
}
}
</code></pre>
<p>当我按下按钮时我调用了这两个函数</p>
<pre><code>saveHighscore (gameScore: score)
overrideHighestScore (gameScore: score)
</code></pre>
<p>控制台正确显示输出,例如,当收集五个点时,输出将是一条消息,称为:</p>
<pre><code>Success! Sending the highscore of 5 to the leaderboard
</code></pre>
<p>但是游戏中心中的变量 score 的值没有发送,并且在第一次访问棋盘时获得了零值</p>
<p>真的希望得到你的帮助。</p>
<p>真诚地,
尤金。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>希望您已正确配置 <a href="https://itunesconnect.apple.com" rel="noreferrer noopener nofollow">https://itunesconnect.apple.com</a> 的排行榜</p>
<p>请引用下面的屏幕</p>
<hr/>
<p> <a href="/image/BJ4f4.png" rel="noreferrer noopener nofollow"><img src="/image/BJ4f4.png" alt="enter image description here"/></a> </p>
<hr/>
<p>还可以引用下面的代码来保存排行榜上的分数。</p>
<pre><code>func saveScoreOnGameCenter()
{
let leaderboardID = 111
let sScore = GKScore(leaderboardIdentifier: leaderboardID)
sScore.value = Int64(10)
GKScore.reportScores(, withCompletionHandler: { (error: NSError?) -> Void in
if error != nil {
print(error!.localizedDescription)
} else {
print("Score submitted")
}
})
}
</code></pre>
<hr/>
<p>希望这可以帮助您找出问题。</p></p>
<p style="font-size: 20px;">关于ios - Swift 3 Game Center 排行榜不保存分数值,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/45941061/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/45941061/
</a>
</p>
页:
[1]