简体   繁体   English

如何根据Sprite Kit中的设备更改屏幕尺寸?

[英]How to change screen size based on device in Sprite Kit?

I noticed a problem that I didn't have before - on iPhone 5 and related devices my game shows black zones on top and bottom. 我注意到以前没有的问题 - 在iPhone 5及相关设备上,我的游戏在顶部和底部显示黑色区域。

I use standard code for it and it shows that skView.bounds.size is 320x480 even on big devices. 我使用它的标准代码,它表明即使在大型设备上skView.bounds.size也是320x480。

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    SKView * skView = (SKView *)self.view;
    skView.showsFPS = YES;
    skView.showsNodeCount = YES;
    //skView.showsPhysics = YES;

    if (!skView.scene) {
        NSLog(@"size: %@", NSStringFromCGSize(self.view.frame.size));
        SKScene * scene = [MainMenuScene sceneWithSize:skView.bounds.size]; //[MyScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
        [skView presentScene:scene];
    }
}

EDIT: It determines iPad sizes correctly. 编辑:它正确地确定iPad尺寸。

EDIT2: changing scene size does not increase its height. EDIT2:改变场景大小不会增加其高度。 I tried setting to 320, 568 manually to no avail. 我尝试手动设置为320,568没有用。

EDIT3: it shows same black stripes on default Xcode project. EDIT3:它在默认的Xcode项目中显示相同的黑色条纹。 Something is very wrong here. 这里有点不对劲。

Here is a screenshot: 这是一个截图:

在此输入图像描述

Somehow Xcode did not provide Default launch images with the project. 不知何故,Xcode没有为项目提供默认启动图像。 After I added launch images it all started working. 在我添加了启动图像之后,它开始工作了。

In https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html , The documentation says 'To let the system know that your app supports the iPhone 6 screen sizes, include a storyboard launch screen file in your app's bundle. https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html中 ,文档说'要让系统知道您的应用支持iPhone 6屏幕大小,请包含故事板启动应用程序包中的屏幕文件。 At runtime, the system looks for a storyboard launch screen file. 在运行时,系统会查找故事板启动屏幕文件。 If such an file is present, the system assumes that your app supports the iPhone 6 and 6 Plus explicitly and runs it in fullscreen mode. 如果存在此类文件,系统会假定您的应用程序明确支持iPhone 6和6 Plus,并以全屏模式运行。 If such an image is not present, the system reports a smaller screen size (either 320 by 480 points or 320 by 568 points) so that your app's screen-based calculations continue to be correct. 如果没有这样的图像,系统会报告较小的屏幕尺寸(320×480点或320×568点),以便您的应用程序的基于屏幕的计算继续正确。 The contents are then scaled to fit the larger screen.'. 然后缩放内容以适应更大的屏幕。'

I solved by selecting 'Project'->'App Icons and Launch Images'->'Launch Image source' and then let Xcode produce the file. 我解决了选择'Project' - >'App Icons and Launch Images' - >'Launch Image source'然后让Xcode生成文件。 It is possible to copy this file in from an older project as well. 也可以从旧项目中复制此文件。 (project made on Xcode 5.1.1 or previous). (在Xcode 5.1.1或之前制作的项目)。

This also happens when creating a project for iOS 8+ in xCode 6 and then try and execute the application on iOS 7 or less. 在xCode 6中为iOS 8+创建项目然后尝试在iOS 7或更低版​​本上执行应用程序时也会发生这种情况。

To change the view size of Your scene you can do this 要更改场景的视图大小,您可以执行此操作

   SKView * skView = (SKView *)self.view;
   CGSize viewSize = self.view.bounds.size;
   viewSize.height *= 2;
   viewSize.width *= 2;
   SKScene * scene = [MainMenuScene sceneWithSize:viewSize];
   scene.scaleMode = SKSceneScaleModeAspectFill;

The scene viewSize will be scale by 2 here . 场景viewSize将在这里缩放2。

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

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