Reputation: 17
I've recently started learning swift and sprite kit. i am currently trying to do the basics and was trying to fit a background image on to the screen. i have managed to get the background picture up and in the centre of the screen but it is not filling up the whole screen. all help would be appreciated.
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
let bgImage = SKSpriteNode(imageNamed: "background.png")
bgImage.position = CGPoint(x:self.size.width/2, y: self.size.height/2)
bgImage.anchorPoint = CGPointMake(0.5, 0.5)
bgImage.zPosition = -1
self.addChild(bgImage)
Upvotes: 0
Views: 1102
Reputation: 59536
You can change the size of your sprite to fit the size the scene
bgImage.size = self.size
Of course if the proportions of the scene are different from the proportions of the sprite, the sprite will be stretched.
Thank you to @Knight0fDragon for the helpful comments below.
Upvotes: 1