0

In the documented SK programming guide by Apple the first displayed scene is "executed" by this code in the 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

Notice that it's a sample project for the iPad, so the view size is fixed (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)?

4

1 回答 1

1

您可以获取设备的大小并使用它,例如:

- (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];
}
于 2014-05-28T13:17:41.987 回答