【问题标题】:Tracking multiple touches as CGPoints in Swift在 Swift 中将多个触摸作为 CGPoints 进行跟踪
【发布时间】:2015-03-16 06:48:28
【问题描述】:

所以这让我难了一阵子。我想在 iPhone 上同时跟踪游戏中的多个触摸,将它们存储为 CGPoints 并实时分析它们的动作(可能在 touchesMoved 函数内)以在游戏中执行动作。

我已经阅读了一些解决方案,但我无法根据我的确切需求对其进行修改。这两个帖子的答案大概是在正确的轨道上:

Multi-touch gesture in Sprite Kit

Get coordinates of multiple touches in Swift

我有一些实现的想法,但它们似乎不起作用,我希望看到更多的想法。非常感谢任何帮助和建议。必须克服这个障碍!

【问题讨论】:

    标签: ios swift sprite-kit touches


    【解决方案1】:

    试试这样的:

    class CustomView: UIView {
       override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
          let touchArray = touches.allObjects as [UITouch]
          println("-----")
          println("\(touchArray.count) touches:")
          for touch in touchArray{
             println(touch.locationInView(self))
          }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      • 1970-01-01
      • 2017-09-12
      • 1970-01-01
      相关资源
      最近更新 更多