更改touch内的touch.name而不再运行?(Change node.name inside of touch without running again?)
我想点击某个spritenode并更改该spritenode的值。 这是问题所在。 当我这样做,并设置一个if语句,它知道去if语句。 但是,我不希望它在下次单击按钮之前运行。
例:
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 } } }有没有办法做到这一点?
I want to click on a certain spritenode and change the value of that spritenode. Here is the problem. When i do that, and set a if statement it knows to go to that if statement. However, i don't want it to run until next time the button is clicked.
Example:
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 } } }Is there a way to do this?
最满意答案
首先,在你的第二个if语句中,你没有检查值“==”你正在为它赋值“=”。
无论如何,解决问题的一个简单方法是添加else if语句。
if node.name == "apple" { appple.name = "orange" print("Hello") }else if node.name == "orange" { //do this }first of all in your second if statement you are not checking the value "==" your are assigning a value "=" to it.
anyway a simple solution to your problem is to add an else if statement.
if node.name == "apple" { appple.name = "orange" print("Hello") }else if node.name == "orange" { //do this }更多推荐
发布评论