1
我正在开发一款使用Sprite的游戏,游戏效果非常好。我试图添加一个功能,允许您更改该GameView的内容。但该功能的按钮位于不同的ViewController上。我将如何能够将代码实现到不同的视图控制器中?在ViewContollers之间共享信息
这是我想要的按钮来实现
for touch: AnyObject in touches {
// Get the location of the touch in this scene
let location = touch.location(in: self)
// Check if the location of the touch is within the button's bounds
if button.contains(location) {
Ghost.texture = SKTexture(imageNamed:"Ghost2")
}
}
代码这里是按钮
@IBAction func button(_ sender: AnyObject) {
} 但按钮上ViewController1和我想改变的对象是on ViewController2(GemScene)
你可以使用NSUserDefault(首选项)共享信息。 –
[视图控制器之间传递数据]的可能重复(http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers) – nbloqs