在swift中开始新游戏场景时,图像会扭曲

时间:2015-08-31 18:47:04

标签: swift uiviewcontroller

转换到新场景时,我无法保持恒定的场景尺寸。新场景在呈现时会略微压缩。

我的GameSceneController是默认代码,如下所示:

class GameViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    if let scene = GameScene.unarchiveFromFile("GameScene") as? 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 = .AspectFill

        skView.presentScene(scene)
    }
  }

当我将场景更改为子视图时:

override func viewWillLayoutSubviews() {
  super.viewWillLayoutSubviews()

  if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
    // Configure the view.
    var 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.size = skView.bounds.size
    scene.scaleMode = .AspectFill

    skView.presentScene(scene)

  }
}

它纠正了问题,但后来我失去了控制器的原始尺寸,图像也被放大了。

0 个答案:

没有答案