SKScene应该是什么尺寸? [英] What size should SKScene be?

查看:138
本文介绍了SKScene应该是什么尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我不指定尺寸时我的SKScene ,我的行为很奇怪,其中节点要么不出现,要么全屏显示.

When I don't specify a size for my SKScene, I get odd behavior where nodes either don't appear, or they appear in full screen.

一种解决方法是使用Apple的入门代码,该代码具有Scene.sks并本质上将大小硬编码为:

One fix is to use Apple's starter code which has a Scene.sks and essentially hardcodes the size to something like:

sceneView.presentScene(SKScene(size: CGSize(width: 750, height: 1334)))

在一个拥有自动布局,不同的屏幕尺寸,尺寸类别,旋转度等的世界中,对场景的宽度和高度进行硬编码似乎不正确.

In a world where we have auto layout, different screen sizes, size classes, rotation, etc. it doesn't seem right to hardcode the width and height of a scene.

指定SKScene大小以使其尊重并适应我设备的尺寸,旋转度等的正确方法是什么?

What's the proper way to specify the SKScene size such that it respects and adapts to my device's dimensions, rotation, etc?

例如,理想情况下,我可以省略尺寸:

For example, I would ideally be able to omit the size:

sceneView.presentScene(SKScene()))

...而是让我自动布局来调整场景的大小.但是,如链接的问题所示,这将导致场景无法正确显示.另外,如果不能选择自动布局,则应该重写哪些方法以确保始终正确实例化/更新我的场景?

... and instead have auto layout resize the scene for me. However, as the linked question shows, this causes the scene to not display properly. Alternatively, if auto layout is not an option, which method(s) should I override to ensure that my scene is always instantiated/updated properly?

我注意到,当我选择了不正确的尺寸(例如200x200)时,它仍会显示节点,但会将它们放大到更大.这使我相信,无论选择什么尺寸,它始终会正确填充相机的输出输出(即不会裁剪任何内容).但是,如果我选择了错误的尺寸,艺术品将无法正确放大/缩小.因此,我现在想知道我是否应该根据设备尺寸确定尺寸,还是根据相机给我的尺寸(例如像素分辨率).

I notice that when I choose an incorrect size (e.g. 200x200), it still shows the nodes, but scales them up to be much larger. This leads me to believe that no matter what size I choose, it'll always fill in the camera output output properly (i.e. nothing will be cropped). However, if I choose the wrong size, the artwork would be scaled up/down improperly. Therefore, I now wonder if I should really be basing the size off of the device's dimensions, or rather off of something that the camera gives me (its pixel resolution, for example).

推荐答案

SpriteKit场景大小可以这样设置:

SpriteKit scene size might be set this way:

let videoNode = SKVideoNode(fileNamed: "video.mov")
    
let skScene = SKScene(size: CGSize(width: planeGeo.width * 1280,
                                  height: planeGeo.height * 720))
    
videoNode.position = CGPoint(x: skScene.size.width / 2,
                             y: skScene.size.height / 2)
    
videoNode.size = skScene.size

skScene.addChild(videoNode)

这篇关于SKScene应该是什么尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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