To animate the hero in the game, drag the
.atlasc folder and the Swift class file into the project. Then, in the
init function, add the following code right after adding the hero to the scene:
let heroAtlas = heroAnim() let heroIdleAnimArray = heroAtlas.hero_Idle_() let animaiton = SKAction.animateWithTextures(heroIdleAnimArray, timePerFrame: 0.2) let animate = SKAction.repeatActionForever(animaiton) hero.runAction(animate)
And that's all! You can build and run the game to see the hero getting animated.
Here, we first create a reference to the Swift class that was created in Texture Packer. Next, we create a constant called
heroIdleArray and assign the array for the idle animation that is already created in the