Sprite Kit 场景编辑器 GameScene.sks 场景宽度和高度 [英] Sprite Kit Scene Editor GameScene.sks scene width and height
问题描述
我正在使用 spritekit 场景构建器来构建我的场景(在 xcode 7 ios9 中创建项目时也称为 GameScene.sks 文件).SpriteKit 在设置屏幕高度和宽度时只使用像素值.我的问题是这样的:
I'm using the spritekit scene builder to build my scene (aka the GameScene.sks file when you create the project in xcode 7 ios9). SpriteKit only uses pixel values when setting the screen height and width. My question is this:
如果我将像素值设置为 iphone 6 的像素值,游戏对于 ipad 和 iphone 6+ 来说会不会太小?为什么没有适合设备屏幕的选项?我应该怎么做才能避免这种情况?
If I set the pixels values to that of an iphone 6, will the game be too small for ipad and iphone 6+? Why is there no option to fit the device screen? What should I do to avoid this?
推荐答案
像素密度
首先,场景的大小是在 Points
而不是 Pixels
中定义的.
Pixel density
First of all the size of the Scene is defined in Points
not Pixels
.
让我们看看支持 iOS 9 的设备是如何处理这个问题的:
Let's see how the devices that support iOS 9 deal with this:
- 1 点 = 1x1 像素: iPad 2、iPad mini
- 1 点 = 2x2 像素: iPhone 4s、iPhone 5、iPhone 5c、iPhone 5s、iPhone 6、iPhone 6s、iPad mini 2、iPad mini 3、iPad mini 4、iPad 3、iPad 4、iPad Air、iPad Air 2、iPad Pro、iPod touch 5、iPod touch 6
- 1 点 = 3x3 像素: iPhone 6 Plus、iPhone 6s Plus
- 1 point = 1x1 pixel: iPad 2, iPad mini
- 1 point = 2x2 pixels: iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPhone 6, iPhone 6s, iPad mini 2, iPad mini 3, iPad mini 4, iPad 3, iPad 4, iPad Air, iPad Air 2, iPad Pro, iPod touch 5, iPod touch 6
- 1 point = 3x3 pixels: iPhone 6 Plus, iPhone 6s Plus
这允许您指定自动转换为特定设备的像素密度的大小.
This allow you to specify a size that is automatically converted for the pixel density of a particular device.
iOS 9 支持的 iPhone/iPad 上有多种屏幕尺寸可供选择.
There are several screen sizes available on the iPhone/iPad supported by iOS 9.
使用 SpriteKit,您可以轻松地设置 Scene
的 scaleMode
属性来解决这个问题.
With SpriteKit you can easily face this problem setting the scaleMode
property of your Scene
.
您可以在 4 个选项中进行选择:
You can chose among 4 options:
- 填充:缩放 SKScene 以填充整个 SKView.
- AspectFill: 缩放 SKScene 以填充 SKView,同时保持场景的纵横比.如果视图有不同的纵横比.
- AspectFit: 缩放 SKScene 以适应 SKView,同时保持场景的纵横比.一些信箱可能会发生,如果视图具有不同的纵横比.
- ResizeFill:修改 SKScene 的实际大小以与 SKView 完全匹配.
- Fill: Scale the SKScene to fill the entire SKView.
- AspectFill: Scale the SKScene to fill the SKView while preserving the scene's aspect ratio. Some cropping may occur if the view has a different aspect ratio.
- AspectFit: Scale the SKScene to fit within the SKView while preserving the scene's aspect ratio. Some letterboxing may occur if the view has a different aspect ratio.
- ResizeFill: Modify the SKScene's actual size to exactly match the SKView.
您可能想要设置 AspectFill
但这确实取决于您的游戏.
You probably want to set AspectFill
but it really depends on your game.
要设置属性打开 GameViewController.swift
(或 .m
,如果你使用 Objective-C),在 viewDidLoad
你会发现这条线.只需根据您的喜好进行更改即可.
To set the property open GameViewController.swift
(or .m
if you use Objective-C), in viewDidLoad
you'll find this line. Just change it to mach your preference.
/* Set the scale mode to scale to fit the window */
gameScene.scaleMode = .AspectFill
这篇关于Sprite Kit 场景编辑器 GameScene.sks 场景宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!