如何缩放窗口以适应所有设备?

时间:2016-07-05 04:14:33

标签: swift sprite-kit

我想知道如何在所有潜水中缩放窗口以适合相同的尺寸。问题是,在一些偏离中,物体不会覆盖我想要的相同空间。

我有我的scaleMode = .ResizeFill,但问题是,如果我做它.AspectFill它不会出现在正确的位置。我认为问题在于我在场景中添加了一个新容器,但我不知道如何解决它。

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

1 个答案:

答案 0 :(得分:1)

  • 问题可能出在您绘制圆圈的代码中,您可能正在绘图 所有屏幕尺寸的半径相同的圆圈。
  • 您需要,而不是绘制具有相同半径的圆 根据设备宽度提供圆的动态半径。

替换此

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

使用以下代码段

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