3
votes

So far the game loads in Portrait: so the main menu is in Portrait and then the game overworld (where the player character roams around in) is also in portrait. But I need to change orientation to landscape mode when the character begins battle (also, when the player turns their phone during battle mode, I don't want the phone to change orientation & accidentally change everything back to Portrait mode or vice-versa). The battle mode is another SKScene that is presented upon certain triggers. How do I change the orientation of a newly presented SKScene to Landscape? Can I perform these changes inside individual SKScene's or only inside the View Controller? Here is the current view controller code, regarding orientation:

-(BOOL)shouldAutorotate
{
    return YES;
}


-(NSUInteger)supportedInterfaceOrientations
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return UIInterfaceOrientationMaskAll;
    }
}

Here is the current code inside the battle SKScene - the one I want to force into Landscape mode (turns out very ugly since the battle scene loads in Landscape but the View Controller still thinks we're in Portrait... Another problem is that if I rotate my phone in any way, the orientation is automatically rotated. I need orientation to be fixed regrading phone movement):

-(void)didMoveToView:(SKView *)view
{
    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
1

1 Answers

0
votes

That's a problem because you can only manually change your app's orientation IF it is already allowed in your app settings. For example, if you only check portrait mode but later want to go to landscape mode, you can't do that.

To change orientation to, for example, landscape left you can use:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft  animated:NO];