ios - 使用 Swift/SKScene 检测触摸

标签 ios swift sprite-kit skspritenode skscene

我正在尝试找出如何使用 SKScene 的子类检测屏幕上任何位置的触摸,以便我可以进行转换。我该怎么做?

谢谢

最佳答案

       override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

      let location = touch.location(in: self)


      print(location)

     //if your touch location = a button or anything it transitions to a new scene 
       if location = //Startbutton {
       let transition = SKTransition.reveal(with: .down, duration: 0.75)
     let gameScene = GameScene(size: size)
     gameScene.scaleMode = scaleMode
     view?.presentScene(gameScene, transition: transition)

打印用户触摸位置...希望对 m8 有帮助

关于ios - 使用 Swift/SKScene 检测触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44399813/

相关文章:

ios - 值存储在数组中但无法访问?

swift - 在 SKScene 的应用内购买

ios - 相互交换 Sprite 位置

ios - UICollectionView 中的 SKView 表现糟糕

iphone - 仅在应用程序处于后台时获取位置更新

android - Chromecast:管理来自发送者 Android 的接收者中的停止事件(不是暂停)

ios - OPENCV iOS安装

swift - SwiftUI 中的旋转木马/侧边栏列表样式

ios - 在 UIScrollView 中缩放 UIImageView – 不居中

ios - Swift:PlayGround 中的 UIWebView 不可见