2017-06-04 65 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 
} 
相关问题