简体   繁体   English

在第二个视图控制器中使用GameScene的得分

[英]Use score from GameScene in second view controller

I am working on an app and I am have GameScene, GameViewController, and a ResetViewController . 我正在开发一个应用程序,并且拥有GameScene, GameViewController, and a ResetViewController I have my scoring method set up in the gameScene, the problem is I need to use the score from my GameScene for a label in my ResetViewController. 我在gameScene中设置了计分方法,问题是我需要将GameScene中的分数用于ResetViewController中的标签。

This is what I have 这就是我所拥有的

In My GameScene 在我的GameScene中

var score: Int = 0
var scoreLabel = SKLabelNode()


//the scoreLabel works fine on the game scene
score++
scoreLabel.text = "\(score)"

I am Needing to display the score on this UiLabel on my resetViewController 我需要在我的resetViewController上显示此UiLabel上的分数

    @IBOutlet weak var YourScore: UILabel!

You could save the value using NSUserDefaults. 您可以使用NSUserDefaults保存该值。 That way the val will be stored for any further use as well. 这样,val也将被存储以用于任何进一步的使用。

How to save to user defaults can be found here How do I save user preferences for my iPhone app? 如何在此处找到如何保存为用户默认值的方法如何为iPhone应用程序保存用户首选项?

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

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