如何更改SKscene大小 [英] How to change SKscene size

查看:80
本文介绍了如何更改SKscene大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我在模拟器中运行我的应用程序时,视图比例总是显示为768,1024,如何将其更改为1024,768.这是默认的尺寸代码 类GameViewController:UIViewController {

every time i run my app in my simulator the view scale always comes out to 768,1024 how do you change this to 1024,768. here is the default size code 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 = .AspectFill

        skView.presentScene(scene)
    }
}

推荐答案

1)如果您使用.sks文件(spriteKit可视编辑器)

1) If you use .sks files (the spriteKit visual editor)

只需转到您项目中的GameScene.sks文件(而不是swift),即可在右侧的检查器中更改场景大小.

Just go to the GameScene.sks file (not swift) in you project where you can change the scene size in the inspector on the right.

您可以在此处查看此文章,如果您向下滚动一点,它们将显示此内容.如果您打算使用可视化编辑器,那么它应该是一个很好的教程.

You can check this article here where they show this if you scroll down a tiny bit. Its a good tutorial you should ready if you plan on working with the visual editor.

https://www.raywenderlich.com/118225/introduction -sprite-kit-scene-editor

2)不使用.sks文件,以代码形式加载场景

2) Not using .sks files, loading scenes in code

如果您不使用.sks文件,则可以删除GameScene.sks文件并像这样加载场景.

If you dont use .sks files you can delete the GameScene.sks file and load the scene like so.

 override func viewDidLoad() {
super.viewDidLoad()

    // Configure the view.
    guard let skView = self.view as? SKView else { return }

    let scene = GameScene(size: CGSize(width: 1920, height: 1080))

    skView.showsFPS = true
    skView.showsNodeCount = true

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

    scene.scaleMode = .AspectFill

    skView.presentScene(scene)
  }

希望这会有所帮助

这篇关于如何更改SKscene大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆