【发布时间】:2025-12-25 03:05:06
【问题描述】:
我正在使用 Sprite 开发游戏,游戏运行良好。我正在尝试添加一个功能,允许您更改该 GameView 上的内容。但是该功能的按钮位于不同的 ViewController 上。我怎样才能将代码实现到不同的视图控制器中?
这是我希望按钮实现的代码
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 上,而我要更改的对象在 ViewController2 (GemScene) 上
【问题讨论】:
-
你可以使用 NSUserDefault (preference) 来分享信息。