Diego Benítez
Diego Benítez

Reputation: 185

how to scale the window to fit in all devices?

I want to know how can I scale the window to fit with the same size in all diveces. The problem is that in some diveces the objects doesnt cover the same space of how I want.

I have my scaleMode = .ResizeFill but the problem is that if I make it .AspectFill it doesnt appear in the correct place. I think that the problem is that I added a new container on the scene, but I dont know how to solve it.

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene(fileNamed:"GameScene") {
        // Configure the view.
        let skView = self.view as! SKView
        skView.showsFPS = true
        skView.showsNodeCount = true

        /* Sprite Kit applies additional optimizations to improve rendering performance */
        skView.ignoresSiblingOrder = true

        /* Set the scale mode to scale to fit the window */
        scene.scaleMode = .ResizeFill
        scene.position = view.center

        skView.presentScene(scene)
    }
}


override func didMoveToView(view: SKView) {
    /* Setup your scene here */

    scaleMode = .ResizeFill
    node.position = view.center
    // 3) Add the container to the scene
    //addChild(node)
    // 4) Set the sprite's x position
    sprite.position = CGPointMake(radius, 0)
    // 5) Add the sprite to the container
    node.addChild(sprite)
    // 6) Rotate the container
    rotate()
    sprite.color = UIColor.whiteColor()
    sprite.colorBlendFactor = 1.0
    sprite.zPosition = 4.0

    circulo = SKSpriteNode(imageNamed: "circuloFondo2")
    circulo.size = CGSize(width: 294, height: 294)
    circulo.color = UIColor(red: 0.15, green: 0.15, blue: 0.15, alpha: 1)
    circulo.colorBlendFactor = 1
    circulo.alpha = 0.35
    circulo.position = view.center
    self.addChild(circulo)
    circulo.zPosition = 1
   }

This is an iPhone 5s enter image description here

Upvotes: 0

Views: 224

Answers (1)

Rohit Pradhan
Rohit Pradhan

Reputation: 3875

  • The issue might be in code where you draw circle,You might be drawing the circle with same radius for all screen sizes.
  • Instead of drawing the circle with the same radius, you need to provide dynamic radius of the circle according to the device width.

Replace this

circulo.size = CGSize(width: 294, height: 294)

Use following snippet

let padding:CGFloat =  40.0  
circulo.size = CGSize(width:view.frame.size.width - padding , height: view.frame.size.width - padding)

Upvotes: 1

Related Questions