简体   繁体   English

如何从GameScene快速访问ViewController中的整数变量

[英]how to access integer variable from GameScene to ViewController in swift

I have a gamecenter button that I added to my GameViewController from the storyboard. 我有一个游戏中心按钮,已从情节提要添加到我的GameViewController中。 I need to use the highscore variable created in my GameScene as my highscore on the leader board. 我需要将在GameScene中创建的highscore变量用作排行榜上的highscore。

let highscore = self.gameScene.highscore

saveHighScore(number: highscore)

I keep getting zero as my score. 我的分数一直保持为零。 What do I do? 我该怎么办?

I found a solution. 我找到了解决方案。 I just had to use 我只需要使用

saveHighScore(number: highscoreDefault.value(forKey: "highscore") as! NSInteger!) saveHighScore(number:highscoreDefault.value(forKey:“ highscore”)as!NSInteger!)

where I had my highscore saved in the phone storage 我的高分保存在手机存储中的位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM