0
votes

Summary

I'm creating an SpriteKit game for different devices and I'm wondering what should be the size of the different assets.

What I have right now

I'm creating the SKScene in viewDidLoad:

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. 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. 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.

I'm using xcassets to provide the background images and I would like to know which sizes should I use. My current configuration is ready for 320 points resolutions (iPhone 4, iPhone 5)

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

The problem

The problem is that the image will be rescaled in following devices:

  • iPhone 6: 750 pixels - 375 points
  • iPhone 6 Plus: 1242 pixels - 414 points
  • iPad: 768 pixels - 768 points
  • iPad retina: 1536 pixels - 768 points

I would like to know how am I supposed to configure the images and the SKScene size to optimise it for all the devices.

2
viewwilllayout is the recommended way, just check self.view == nil before presenting the sceneLearnCocos2D
also check scene scaleModeLearnCocos2D
I've already tried it and it initialises it at 600 pixels width in the first call and then to the correct 750 (iPhone 6) width. If I check that the scene is nil, it will be initialised at 600 pixels width, the same as in viewDidLoad.Octan
I can do it correctly in the first call of viewDidLayoutSubviews (Notice the Did instead of Will) Do you think this is a good idea?Octan

2 Answers

1
votes

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

For a project I'm currently working on, I decided to make my assets in the largest possible resolution, i.e. the one of the 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

scene.scaleMode = .AspectFit

On iPad and iPhone 4s, this will result in a border, but I can live with that.