dimanche 28 août 2016

Swift - How to check to see if sprite is assigned to certain image

Currently, in my code, I have an SKSpriteNode named ball which randomly changes texture when it makes contact with anything. There are 4 different textures each with a different colored ball. I want to use an if else statement to check to see if the ball is equal to a specific texture so it can do an action.

I have this code so far, but it does not work

func didBeginContact(contact: SKPhysicsContact) {

    if ball.texture == SKTexture(imageNamed: "ball2") {

        print("Color Matched")

    } else {

        print("Color does not match")
    }


}

The if ball.texture == .... line is not working

Aucun commentaire:

Enregistrer un commentaire