if statement - Swift - How to check to see if sprite is assigned to certain image -
currently, in code, have skspritenode named ball randomly changes texture when makes contact anything. there 4 different textures/images each different colored ball. want use if else statement check see if ball equal specific texture can action.
i have code far, not check texture of ball sprite
func didbegincontact(contact: skphysicscontact) { if ball.texture == sktexture(imagenamed: "ball2") && platform3.position.y <= 15 { print("color matching") } else { print("not matching") } }
the if platform3.position.y <= 25 part works, ball.texture part of code not check see texture ball has.
set user data when assign color ball.
ball.userdata = ["color": 1] // later can check if (ball.userdata["color"] == 1) {
that proper way do. comparing integer faster.
Comments
Post a Comment