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")
self.addChild(bgImage)
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.
https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKSpriteNode_Ref/

  1 comment for “Setting up a background programmatically with swift

  1. April 29, 2017 at 1:56 PM

    Thanks for the article post.Really looking forward to read more.

Leave a Reply

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