SKScene iPad height width reversed

前端 未结 2 1806
慢半拍i
慢半拍i 2021-01-18 10:55

I am trying to fill my SKScene with tiles, in an iPad app that only supports landscape mode. Within the scene I detect h & w as such:

int h = [UIScreen          


        
2条回答
  •  青春惊慌失措
    2021-01-18 11:30

    It doesn't make sense to initialize the scene in the layout handler. Resize the scene in the layout handler. (That's what it's for.)

    @implementation SGOMyScene
    {
        SKScene *scene;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        SKView *skView = (SKView *)self.view;
        skView.showsFPS = YES;
        skView.showsNodeCount = YES;
    
        scene = [SGOMyScene sceneWithSize:skView.bounds.size];
        scene.scaleMode = SKSceneScaleModeAspectFill;
    
        [skView presentScene:scene];
    }
    
    - (void)viewWillLayoutSubviews
    {
        [super viewWillLayoutSubviews];
    
        SKView *skView = (SKView *)self.view;
        scene.size = skView.bounds.size;
    }
    

    Your scene should implement - (void)didChangeSize:(CGSize)oldSize to move everything into the right place.

    Hooray, now your game handles device rotations too.

提交回复
热议问题