2015-09-27 129 views
2

我在隱藏和顯示SKSpriteNode時遇到問題。 但是,我確定使用hidden = true會隱藏可見性。我想要做的是在按下標題時顯示圖像按鈕,並在除標題以外的其他地方按下時隱藏圖像按鈕。我有下面的示例代碼。我很想聽到你的消息。無法隱藏/取消隱藏SKSpriteNode

startSprite.position = CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.5+startSprite.size.height) 
self.addChild(startSprite) 
startSprite.zPosition = 3 
startSprite.hidden = true 
startSprite.name = "start" 


//When the title is pressed show the startSprite 
//clicking a image 
if touchNode.name == "normal" { 
    startSprite.hidden = false 
    if touchNode.name == "start" { 
    //start the game when the startSprite is pressed 
    } else { 
     startSprite.hidden = true 
    } 
} 

回答

3

如果我抓住你的意思,你想顯示startSprite當按下標題(其namenormal,而當按下除了標題其他地方躲startSprite。我建議你給每個節點name然後將它添加到場景中,這樣就很容易分辨出你觸摸的是哪個物件,希望這會有所幫助:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {   
    for touch in touches { 
     let location = touch.locationInNode(self) 
     let touchNode = self.nodeAtPoint(location) 

     if touchNode.name == "normal" { 
      startSprite.hidden = false 
     } else { 
      startSprite.hidden = true 
     } 
    } 
} 
+0

謝謝!它確實有幫助。 – user3264924