简体   繁体   English

SpriteKit正确的资产大小

[英]SpriteKit correct asset size

Summary 摘要

I'm creating an SpriteKit game for different devices and I'm wondering what should be the size of the different assets. 我正在为不同的设备创建SpriteKit游戏,我想知道不同资产的大小应该是多少。

What I have right now 我现在有什么

I'm creating the SKScene in viewDidLoad : 我在viewDidLoad创建SKScene

scene = GameScene(size: view.bounds.size)
scene.scaleMode = .AspectFill

I don't want to use viewWillLayoutSubviews because it is called twice on start up and also each time the device is rotated. 我不想使用viewWillLayoutSubviews因为它在启动时以及每次设备旋转时都会被调用两次。 I don't think that initialising the scene here is a good idea. 我认为初始化场景不是一个好主意。

With this configuration, my view is initialised with a width of 600 points (default storyboard size) and then rescaled to the device width. 使用此配置,我的视图被初始化为600点的宽度(默认情节提要板大小),然后重新缩放为设备的宽度。 Using println(scene.size.width) after the view has been layout it displays a 375 points size in the iPhone 6 and 414 points in the iPhone 6 Plus. 在布局视图之后,使用println(scene.size.width)在iPhone 6中显示375点的尺寸,在iPhone 6 Plus中显示414点的尺寸。

I'm using xcassets to provide the background images and I would like to know which sizes should I use. 我正在使用xcassets提供背景图像,我想知道应该使用哪种尺寸。 My current configuration is ready for 320 points resolutions (iPhone 4, iPhone 5) 我当前的配置已准备好获得320点分辨率(iPhone 4,iPhone 5)

  • 1x : 320 pixels 1x :320像素
  • 2x : 640 pixels 2x :640像素
  • 3x : 960 pixels 3x :960像素

The problem 问题

The problem is that the image will be rescaled in following devices: 问题在于图像将在以下设备中重新缩放:

  • iPhone 6 : 750 pixels - 375 points iPhone 6 :750像素-375点
  • iPhone 6 Plus : 1242 pixels - 414 points iPhone 6 Plus :1242像素-414点
  • iPad : 768 pixels - 768 points iPad :768像素-768点
  • iPad retina : 1536 pixels - 768 points iPad视网膜 :1536像素-768点

I would like to know how am I supposed to configure the images and the SKScene size to optimise it for all the devices. 我想知道如何配置图像和SKScene大小以针对所有设备进行优化。

If you don't want to initialize scene twice you can initialize it only once: 如果不想初始化场景两次,则只能初始化一次:

- (void)viewWillLayoutSubviews
{

    [super viewWillLayoutSubviews];


    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;
    skView.showsDrawCount = YES;
    skView.showsPhysics = YES;
    skView.ignoresSiblingOrder = YES;

    if(!skView.scene){
    // Create and configure the scene.
        GameScene * scene = [GameScene sceneWithSize:skView.bounds.size];

        scene.scaleMode = SKSceneScaleModeAspectFill;

    // Present the scene.
        [skView presentScene:scene];
    } 
}

For a project I'm currently working on, I decided to make my assets in the largest possible resolution, ie the one of the iPhone 6 Plus (2208 x 1242, iOS Resolution Reference ). 对于我当前正在从事的项目,我决定使资产达到最大可能的分辨率,即一部iPhone 6 Plus(2208 x 1242, iOS Resolution Reference )。 Since iPhone 6 and iPhone 5 use a 16:9 aspect ratio, it is no problem to down-scale the assets implicitly with 由于iPhone 6和iPhone 5使用的宽高比为16:9,因此使用

scene.scaleMode = .AspectFit

On iPad and iPhone 4s, this will result in a border, but I can live with that. 在iPad和iPhone 4s上,这将导致边框,但是我可以接受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM