我创建了一个容器节点以一键放入所有需要移动的所有SKSpriteNodes,我可以在iOS 8中正常检测到它们的触摸,但是在iOS 7中,我只能检测到主节点上的触摸,当我触摸一个SKSpriteNode,它在容器节点中什么都没有发生。如何解决此问题?

let lvlsNode = SKNode()



override func didMoveToView(view: SKView) {

            self.addChild(lvlsNode)

            axe = SKSpriteNode(imageNamed:"axe")
            axe.anchorPoint = CGPointMake(1, 0)
            axe.size = CGSizeMake(axe.size.width/1.4, axe.size.height/1.4)
            axe.position = CGPointMake(0+screenWidth/7, shield.position.y-shield.size.width*1.4)
            axe.zPosition = 12
            axe.name = "axe"
            lvlsNode.addChild(axe)
}
 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        /* Called when a touch begins */

        for touch in (touches as! Set<UITouch>) {
            let location = touch.locationInNode(self)
            let node = nodeAtPoint(location)

          if node.name == "axe" {
             // do something.... this work in iOS8 but not in iOS 7.1
           }

最佳答案

Yournode.name = "nodeX"

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
   let touch = touches.first as UITouch!
   if atPoint((touch?.location(in: self))!).name == Yournode.name {
       //Your code
   }
}

关于ios - 检测SKNode上的触摸(快速),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31844889/

10-14 21:04
查看更多