user3545063
user3545063

Reputation: 811

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:

- (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)?

Upvotes: 0

Views: 640

Answers (1)

lucianomarisi
lucianomarisi

Reputation: 1552

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];
}

Upvotes: 1

Related Questions