SpriteKit使图像适合屏幕,而不是过去

时间:2016-08-12 07:16:12

标签: swift sprite-kit sizing

我正在开发一个项目,并且SKNodes没有根据设备大小动态调整大小。

示例:

Image one enter image description here

我想在第一张图片上发生的事情发生在第二张图片上。 有什么可以让这种情况自动发生吗?

显示图像的当前大小:

    background.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    background.size = CGSize(width: background.size.width / 5.5, height: background.size.height / 5.5)

GameViewController:

import UIKit
import SpriteKit

class GameViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    // Configure the view.
    let skView = self.view as! SKView
    skView.showsFPS = false
    skView.showsNodeCount = false

    let scene = GameScene(size: skView.bounds.size)

    scene.controller = self
    scene.size = skView.bounds.size

    /* 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 shouldAutorotate() -> Bool {
    return true
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
        return .AllButUpsideDown
    } else {
        return .All
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Release any cached data, images, etc that aren't in use.
}

override func prefersStatusBarHidden() -> Bool {
    return true
}
}

1 个答案:

答案 0 :(得分:0)

如果您希望在具有更大屏幕的设备上展示游戏时调整整个场景的大小,则只需打开GameViewController.swift并确保使用AspectFill

scene.scaleMode = .AspectFill