I am trying to create a simple animation (with 3 textures) that should run only once every time the player dies. I have written the code below by looking online for how to change textures and make the program wait between changing the textures (I wanted to do it this way and not with an atlas because it is only 3 textures).
The game works, so that the ball stays at the position where it dies. Then it stays at that position while the print(I waited) prints 3 times. However, in between the waits the texture of my ball does not change. That is the only thing not working in the code below.
How can I make this code work, or is there another simple way of creating a one time animation?
override func update(_ currentTime: TimeInterval) {
//CHECK IF BALL IS INSIDE THE MAP
if (map_1_buffer.contains(ball.position)) {
} else {
let texture1 = SKTexture(imageNamed: "death_1")
let texture2 = SKTexture(imageNamed: "death_2")
let texture3 = SKTexture(imageNamed: "death_3")
let normal = SKTexture(imageNamed: "Ball1")
ball.texture = texture1
sleep(UInt32(2))
print("i waited 1")
ball.texture = texture2
sleep(UInt32(2))
print("i waited 2")
ball.texture = texture3
sleep(UInt32(2))
print("i waited 3")
ball.texture = normal
death += 1
ball.physicsBody?.velocity.dx = 0
ball.physicsBody?.velocity.dy = 0
ball.position = CGPoint(x: -120, y: 40)
}
}
ballDyingthat's initiallyfalse, set that totruewhen you are about to run the animation, guard themap1_buffer.containscheck with&& !ballDying, and haveresetBallclear the flag again. - bg2b