SKLabelNode will disappear but is still clickable

后端 未结 2 1136
傲寒
傲寒 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:40

    Your labelNode may not be inside the SKScene anymore. This does not mean that it will not respond to the containsPoint function. The labelNode still has a position assigned to it and it can calculate if a point falls inside it using containsPoint function.

    Instead you can try this.

    override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
    
        let touch = touches.anyObject() as UITouch
        let location = touch.locationInNode(self)
    
        if self.nodeAtPoint(location) === lemonadeLabel {
    
            println("lemonadeLabel pressed")
            lemonadeLabel.removeFromParent()
    
        }
    
    }
    

提交回复
热议问题