Sprite Kit game: Over the world in portrait mode, but battles in landscape mode?

While the game is loading into Portrait: so the main menu is in Portrait and then the game world (where the player character moves) is also in the portrait. But I need to change the orientation in landscape mode when the character starts the battle (also when the player turns their phone during combat mode, I don't want the phone to change orientation and accidentally change everything back to portrait mode or vice versa). another SKScene that shows up on some triggers. How do I change the orientation of the newly introduced SKScene to Landscape? Can I make these changes inside a separate SKScene or just 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 in the SKScene battle - the one I want to force in landscape mode (turns out to be very ugly since the battle scene is loaded into Landscape, but the view controller still thinks we are in a portrait ... Another problem is that if i rotate my phone in any way the orientation is automatically rotated. I need orientation to fix the movement of the phone):

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

      

+3


source to share


1 answer


This is a problem because you can only change its orientation manually if it is already allowed in your application settings. For example, if you are only viewing portrait mode, but later want to switch to landscape mode, you cannot do that.

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



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

      

0


source







All Articles