I am working on a universal portrait game and whenever I try different CGPoint sizes, my background image gets cropped. Even width/2 and height/2 makes the image get cropped to the middle. What should the size be to fill up the whole screen for all devices?. Thanks in advance.
import SpriteKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
backgroundColor = SKColor.black
let background = SKSpriteNode(imageNamed: "background")
background.position = CGPoint(x: size.width/2, y: size.height/2)
addChild(background)
}
}
Hello @abd1kadir
Just add one line, give size to SKSpriteNode
same as screen size.
background.size = view.frame.size //self.frame.size //self.view.frame.size
or
background.size = UIScreen.main.bounds.size
Just like :
let background = SKSpriteNode(imageNamed: "background")
background.size = view.frame.size //self.frame.size //self.view.frame.size
background.position = CGPoint(x: size.width/2, y: size.height/2)
addChild(background)
Thanks for the reply but it is not working. This is what I keep getting
I presume you figured this out already but I just discovered the solution and thought I’d put it here in the event someone else had this problem.
When I set up the SKScene itself attached to the SKView, I had to make the scene the same size as the screen.
let scene = myScene(size: UIScreen.main.bounds.size)
let skView = self.view as! SKView
skView.ignoresSiblingOrder = true
scene.scaleMode = .aspectFill
skView.presentScene(scene)
@slogbelly Thank you for sharing your solution - much appreciated!