Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,581
4,764
Isla Nublar
Hi guys,

I'm trying to work in Sprite Kit and am finding the screen sizing incredibly frustrating. If I start with a blank scene, the self.frame.size.width returns 1024 on iPhone 6, not the expected 1334 for pixels, or 667 in points (points being another mess of confusion).

Nowhere in the code is there a spot that sets the frame size to 1024, where does this value come from? Is querying the frame not the right way to get a screens size?

I know I can manually set it correctly in the viewWillLayoutSubviews method but I'm trying to figure out where it comes from. Any help is greatly appreciated. And yes, I've read through Apples sprite kit programming guide which isn't helpful with regards to creating graphics or managing screen sizes.
 

firewood

macrumors G3
Jul 29, 2003
8,135
1,374
Silicon Valley
Make sure to wait for the app to finish laying out all its visible views. If you ask before (auto-)layout is finished, you can get bogus sizes (xib or storyboard defaults unrelated to the device).
 

chrono1081

macrumors G3
Original poster
Jan 26, 2008
8,581
4,764
Isla Nublar
Make sure to wait for the app to finish laying out all its visible views. If you ask before (auto-)layout is finished, you can get bogus sizes (xib or storyboard defaults unrelated to the device).


Thank you. How would I go about doing that? I see people say don't use viewDidLoad and instead use viewWillLayoutSubviews but this doesn't appear to work in iOS 8. Nothing appears at all if I move the view configuration into viewWillLayoutSubviews.

Any idea if there is some different way?

EDIT: I found a way, I can do this: (The scene.size = skView.bounds.size line is the key).

Code:
- (void)viewDidLoad

{

    [superviewDidLoad];

    // Configure the view.

    SKView * skView = (SKView *)self.view;

    skView.showsFPS = YES;

    skView.showsNodeCount = YES;

    /* Sprite Kit applies additional optimizations to improve rendering performance */

    skView.ignoresSiblingOrder = YES;


    // Create and configure the scene.

    GameScene *scene = [GameSceneunarchiveFromFile:@"GameScene"];

    scene.size = skView.bounds.size; //This is the key!

    scene.scaleMode = SKSceneScaleModeAspectFill;


    // Present the scene.

    [skView presentScene:scene];

}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.