Adding character animation

To make sure that the correct animation gets played when the player runs and jumps, we have to extract the run and jump animations from the collada file.

In the Hero class's create function, after updating the anchor point, add the following code to get the run and jump animations:

 // get the animation keys and store it in the anims let animKeys = monsterNode.animationKeys.first let animPlayer = monsterNode.animationPlayer(forKey: animKeys!) let anims = CAAnimation(scnAnimation: (animPlayer?.animation)!) // get the run animation from the animations let runAnimation = Hero.animation(from: anims, startingAtFrame: 31, endingAtFrame: 50) runAnimation.repeatCount = .greatestFiniteMagnitude runAnimation.fadeInDuration = 0.3 ...

Get Swift Game Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.