3

I have created a container node to put in all my SKSpriteNodes that need to be moved all in one touch, I can detect touches on them normally in iOS 8 but in iOS 7 I can only detect touches on my main node and when I touch an SKSpriteNode that it's in the container node nothing happens.. How can I fix this?

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
           }
Ludyem
  • 1,709
  • 1
  • 18
  • 33
  • 1
    What happens when you log the node? Is it null? Place a breakpoint just beneath the line "let node = nodeAtPoint(location)" and inspect node. What does it say? – Philip Aug 06 '15 at 07:58
  • it show me the SKSpriteNode that it's behind axe, if I print(node.name) I get nil for every SpriteNode in the container node – Ludyem Aug 06 '15 at 08:28
  • Ok that is because you are actually pressing that node. What kind of node is it? Could you attach the axe to that node? If so you could check if node.name == nil then you could check node.child/parent.name and see if that is the axe name – Philip Aug 06 '15 at 08:36

1 Answers1

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
   }
}
dig
  • 247
  • 1
  • 7