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

Adding a background and a hero

We are going add the background first, so we can copy and paste the same code from the MainMenuScene into the init function right after where we initialized viewSize:

let BG = SKSpriteNode(imageNamed: "BG")
BG.position = CGPoint(x: viewSize.width/2, y: viewSize.height/2)
self.addChild(BG)

Next we will add the hero sprite. Similar to how we created the BG image asset, create a new asset called hero and assign hero.png and hero2.png to the 1x and 2x slots.

Next we want the hero to be a global variable aswell, as we will need to refer to her outside of the init function. So, right under where we created the viewSize property, add the following line of code at the top of the class:

let hero:SKSpriteNode! 

Next, in the init ...

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