SKLabelNode will disappear but is still clickable

后端 未结 2 1141
傲寒
傲寒 2021-01-24 07:58

I am making a game using SpriteKit and Swift, running Xcode 6. I have an SKLabelNode, let\'s call it myLabelNode for this example. When I call my

2条回答
  •  故里飘歌
    2021-01-24 08:49

    You are trying to determine if the constrainPoints' location are being touched. Even if you remove the label from the scene, it is still an object in memory, i.e: you could re-ad it later.. it still has all it's properties including position, etc..

    I would try this instead:

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    
        for touch: AnyObject in touches {
            if nodeAtPoint(touch.locationInNode(self)) == lemonadeLabel {
                println("lemonadeLabel pressed")
                lemonadeLabel.removeFromParent()
            }
        }
    }
    

    You basically determine if the lemonadeLabel is the node at that position, if yes you remove it. Since you compare with the added node in the scene, if it's gone, it will not be there for comparison ;)

提交回复
热议问题