3

我创建了一个容器节点来放入所有需要一键移动的 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
           }
4

1 回答 1

0
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
   }
}
于 2018-01-14T16:42:23.330 回答