O'Reilly logo

Learning iOS 8 Game Development Using Swift by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Animating the hero

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 heroAnim.swift

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required