I've been working on a Spritekit indie game project for about 5 months and I've come to a point where I have to make my hero fly, and use a texture animation for the wings to flap. When the "fly mode" starts and the hero jumps the wings have to show and start flapping. For this I made 3 distinct animations:
wigsOpenAnimation = SKAction.repeatAction(openAtlasAnimation, count: 1)
wingsFlapAnimation = SKAction.repeatActionForever(flapAtlasAnimation)
wingsCloseAnimaiton = SKAction.repeatAction(closeAtlasAnimation, count: 1)
and then a sequence to join the open animation with the first flap animation:
wingsSequence = SKAction.sequence([wingsOpenAnimation,wingsFlapAnimation])
However, when the hero lands has to close his wings, and this is the piece of code I used to do so:
if (self.onGround == true) || (self.flyMode == false) {
if String(wings.texture).rangeOfString("Flap8") != nil {
wings.runAction(SKAction.waitForDuration(wingsFrequency)) {
self.wings.removeActionForKey("wingsSequence")
self.wings.runAction(self.wingsCloseAnimaiton)
}
}
}
I put this piece of code in the update function, and "Flap8" is the last flap frame texture. The problem is that with this code, immediately before starting the close animation, Flap1 shows again, so it's like the Flap sequence starts again. This is bad because the texture are made so that the close animation has to come immediately after the last flap frame, and having another flap frame in between doesn't look good. Any possible solutions are welcome. I hope I was clear enough, and thanks.