1
votes

I've just finished up on my game in XCode and the animations I have on the nodes when a level is complete, are simple SKAction fade out animations. I know I can incorporate animations in a single view application with Swift Via Cocoapods, but I do I add them into a Sprite kit game? Animations such as Shake animations or bounce animations. A very broad and newbie question but I'd like to know. Thank you.

1

1 Answers

1
votes

Depends what kind of animations you want and how they are being applied to the Node.

For a simple shake animation that you want to apply to a Node you can use an SKAction.

let someNode = SKSpriteNode(imagedNamed: "SomeNode")
addChild(someNode)

let rotateActionOne = SKAction.rotateByAngle(degToRad(-3.0), duration: 0.1)
let rotateActionTwo = SKAction.rotateByAngle(0.0, duration: 0.1)
let rotateActionThr = SKAction.rotateByAngle(degToRad(3.0), duration: 0.1)

let shakeSequence = SKAction.sequence([rotateActionOne, rotateActionTwo, rotateActionThr])
someNode.runAction(shakeSequence) //or someNode.runAction(SKAction.repeatActionForever(sequence))

If you want a full tutorial on this above example visit, https://www.raywenderlich.com/96822/sprite-kit-tutorial-drag-drop-sprites, there is some great tutorials!

If you want to apply a 'bounce' animation you can use Sprite-Kits built in physics engine. Simply apply a SKPhysicsBody to a SKNode. Create another SKPhysicsBody (such as a ground floor), using the categoryBitMask, collisionBitMask and contactBitMask. You can then bounce the node off of the ground. Tweak the restitution, friction, and linearDamping to create a better physics effect.

Another option for animations would be to actually draw out the animation in a PNG animation editor (Adobe Animate CC). Key-frame animation can be a way to get really complex looking animations with out having to be computationally heavy. However this requires a pretty good artistic ability (and quite a bit of time). You can render out the animations and put it into a SKTextureAtlas and then just animate the texture atlas to produce the animation.

Hopefully this somewhat helps!