I am trying to create a specific type of animation that requires a sound and animation to occur for exactly 1 second per texture cycle.
Each time someone clicks a button, it appends a new texture to an array of SKTextures[], then I have an SKSpriteNode animate through each of the textures once. Only problem is, I can't seem to figure out a way to play a sound file for each texture as it animates. I would also like to create an animation for each texture the SKSpriteNode changes to as it goes through the textures.
Here is an example of the flow:
Button Clicked
Append SKTexture array
SKSpriteNode.animateUsingTextures(SKTextureArray, timePerFrame: 1)
While each individual texture displays, animate it, play sound.
Here is what I have that is not working.
(Code is just an abstraction of what I have)
var textures: [SKTexture] = []
let sprite: SKSpriteNode()
let scaleUp = SKAction.scaleTo(300, duration: 0.2)
let scaleDown = SKAction.scaleTo(200, duration: 0.2)
let popAnimation = SKAction.sequence([scaleUp, scaleDown])
func buttonClicked() {
textures.append("Specific Texture")
sprite.animation() // Calls Animation Function
}
func animation() {
let sound = SKAction.playSoundFileNamed("DisplayGesture.mp3", waitForCompletion: true)
let animation = SKAction.animateWithTextures(textures, timePerFrame: 1)
let completeAnimation = SKAction.group([sound, animation, popAnimation])
sprite.runAction(completeAnimation)
}