Setting up a background programmatically with swift

At first I had a difficult time searching for the method to set up the background with SWIFT since, I was totally new to it. But after couple of hours I was able to find the solution for it.

Before using the custom background image I was simply using the UIColor for the background.

self.backgroundColor = UIColor.cyanColor()

Unlike in android development, you will have to use the sprite node to set up the background. After setting the bgImage to the View, set the bgImage’s size to the View’s size it’s self to fill the entire screen.

let bgImage = SKSpriteNode(imageNamed: "mainback")
bgImage.anchorPoint = CGPoint(x:0, y:0)
bgImage.size = self.size

At first I found apple’s documentations hard but as time passed by I started to get used to it.But I still find android developers site much easier to understand.

Leave a Reply

Your email address will not be published. Required fields are marked *