Change node.name inside touch without restarting?

I want to click on a specific spritenode and change the value of that spritenode. Here's the problem. When I do that and set the if statement, it knows to jump to that if statement. However, I don't want it to run until the next button press.

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?

+3


source to share


1 answer


first of all, in your second if statement, you are not checking the "==" value, you are assigning the "=" 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
}

      

+2


source







All Articles