Search code examples
iosswiftsprite-kittouchuniversal

Touch functions do not work properly in iOS


I am making an universal SpriteKit game. I test my game both iPhone and iPad. In iPhone everything works fine and also in simulator but in iPad touch functions do not work properly on the Game Scene. For example; in game scene I have 4 sprites I can touch one of them but the others don't work in iPad. Have any ideas ? What is going on ?

    for touch in touches {
        let location = touch.locationInNode(self)
        for var i=1; i<ballNode.count; i++ {
            if nodeAtPoint(location) == ballNode[i].node && !ballNode[i].character.locked  {
                ballNode[i].touchingNode = true
                ballNode[i].angelLabel.hidden = false



                let seq = SKAction.sequence([fadeIn, fadeOut])
                ballNode[i].node.childNodeWithName("laserAni")!.hidden = false
                ballNode[i].node.childNodeWithName("laserAni")!.runAction(SKAction.repeatActionForever(seq))

                if ballNode[i].node.name == BallTypes.multipleGuns {
                    ballNode[i].node.childNodeWithName("laserAni2")!.hidden = false
                    ballNode[i].node.childNodeWithName("laserAni2")!.runAction(SKAction.repeatActionForever(seq))

                }

            }

        }

Solution

  • So I think that there is some kind of bug here.

    First of all, you start looping in the array at index 1, which is actually the second element in the array. Ballnode[0] is the first index. Unless you are keeping this index blank, then no device at all should be able to access the first element. Second of all, if you noticed that when you moved position of the sprites you could access them, then that means some of them overlapped. You should check your images and crop them or edit as necessary to make sure they fit without overlapping. iOS 9 is known to have many bugs and it seems like you might have discovered one. My advice here is to trust iOS 8 as your default testing OS.