简体   繁体   English

在Sprite Kit中为场景设置通用尺寸

[英]Setting a universal size for a scene in Sprite Kit

In the documented SK programming guide by Apple the first displayed scene is "executed" by this code in the ViewController: 在Apple记录的SK编程指南中,第一个显示的场景是由ViewController中的以下代码“执行”的:

- (void)viewWillAppear:(BOOL)animated
{
HelloScene* hello = [[HelloScene alloc] initWithSize:CGSizeMake(768,1024)];
SKView *spriteView = (SKView *) self.view;
[spriteView presentScene: hello];
}

Source: https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/GettingStarted/GettingStarted.html 来源: https : //developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/GettingStarted/GettingStarted.html

Notice that it's a sample project for the iPad, so the view size is fixed (768, 1024). 请注意,这是iPad的示例项目,因此视图大小是固定的(768,1024)。 How do I set it up, so that it could scale up nicely on an iPhone 4/5 (and probably the next gen iPhone)? 如何设置它,以便可以在iPhone 4/5(以及下一代iPhone)上很好地扩展?

You could get the device's size and use this, for example: 您可以获取设备的大小并使用它,例如:

- (void)viewWillAppear:(BOOL)animated
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGSize screenSize = screenRect.size;
    HelloScene* hello = [[HelloScene alloc] initWithSize:screenSize];
    SKView *spriteView = (SKView *) self.view;
    [spriteView presentScene: hello];
}

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

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