游戏场景到视图控制器

时间:2017-01-01 17:56:48

标签: ios swift

如何使用Swift 3将游戏场景链接到视图控制器?

我刚刚创建了一个按钮,但我在函数touchesEnded上创建的链接不起作用。

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    let touchLocation = touch!.location(in: self)

    if buttonHome.contains(touchLocation) {
        print("tapped!")
        let home:UIViewController = FirstViewController()
        self.view?.window?.rootViewController!.present(home, animated: true, completion: nil)
    }
}

1 个答案:

答案 0 :(得分:0)

我假设您在游戏场景类中使用Xcode ..您应该将视图控制器设置为一个变量来分配..这是伪代码

Class your-game-scene {
    Var viewcontroller :: gameviewcontroller

}

您可能需要实例化新的声明,因此找到游戏控制器的配置文件并将其设置为您在班级中设置的视图控制器

相关问题