2017-06-04 30 views
3

我想單擊某個spritenode並更改該spritenode的值。這是問題。當我這樣做,並設置一個if語句,它知道要去那個if語句。但是,我不希望它在下次單擊該按鈕時運行。在觸摸裏面改變node.name而不再運行?

例子:

apple.name = "apple" 

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    for touch in touches { 
     let location = touch.location(in: self) 
     let node : SKNode = self.atPoint(location) 
     if node.name == "apple" { 
      appple.name = "orange" 
      print("Hello") 
     } 
     if node.name = "orange" { 
     //do this 
} 

    } 
} 

有沒有辦法做到這一點?

回答

2

首先在你的第二條if語句中,你沒有檢查值「==」,你正在給它賦值「=」。

反正你的問題的一個簡單的解決方案是添加一個else if語句。

if node.name == "apple" { 
     appple.name = "orange" 
     print("Hello") 
    }else if node.name == "orange" { 
    //do this 
} 
相關問題