I\'m working on a game but can\'t figure out the right way to scale/ position everything. I have a universal app and when I switch from device to device the nodes aren\'t in
To keep my games universal I make all my node
s sizes and positions dependant on SKScene
size
Instead of using hardcoded numbers try using proportions from your SKScene
size. For example:
Instead of writing this:
node.position = CGPointMake(100, 100)
Write somthing like this:
node.position = CGPointMake(world.frame.size.width / 32 * 16, world.frame.size.height / 18 * 9)
world -
SKNode
of exactly same size as yourSKScene
Same for sizes
let blackSquare = SKSpriteNode(texture: nil, color: UIColor.blackColor(), size: CGSizeMake(world.frame.size.width / 32, world.frame.size.width / 32))
Also GameViewController
should look something like this:
override func viewDidLoad() {
super.viewDidLoad()
// Configure the view
let skView = view as! SKView
skView.multipleTouchEnabled = false
// Create and configure the scene
let scene = GameScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
scene.size = skView.bounds.size
skView.presentScene(scene);
}
Was this helpfull?