Sprite Kit场景编辑器GameScene.sks场景的宽度和高度 [英] Sprite Kit Scene Editor GameScene.sks scene width and height

查看:59
本文介绍了Sprite Kit场景编辑器GameScene.sks场景的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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 (如果使用Objective-C,则打开 .m ),在 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屋!

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