set the device orientation from landscape to portrait manually

hi all,

I want the orientation of my game at first scene is the lanscape*_ and at the second scene is portrait*_

where use the cocos2d-x 1.x , I can use
CCDirector::sharedDirector()->setDeviceOrientation(....)

but I am using cocos2d-x 2.0, this method is dismissed,
Is there any other method?

thank you so mush

Hi,I met this question too!
If u found the solution,please tell me!
Thank u!
Derek Qu wrote:

hi all,
>
I want the orientation of my game at first scene is the lanscape*_ and at the second scene is portrait*_
>
where use the cocos2d-x 1.x , I can use
CCDirector::sharedDirector()->setDeviceOrientation(....)
>
but I am using cocos2d-x 2.0, this method is dismissed,
Is there any other method?
>
thank you so mush

Hi all,
I have the same problem. I tried to upgrade cocos engine from cocos0.13.0-beta to cocos2d-2.0-x-2.0.4 but there is missing function setDeviceOrientation in ios version.
Isn’t possible to reinitialize somehow that opengl window?
Because of lack of this function I can’t upgrade engine and it looks that this attempt for upgrade was wasting of time. :frowning:

Hi,
You can’t no more use setDeviceOrientation to change the device orientation at runtime.
Please have a look at http://www.cocos2d-x.org/news/62 (bottom of the page) and http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Device_Orientation.

Hi all,
I have the same problem. I have try the method in [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Device_Orientation]].
but I have not found the function didRotateFromInterfaceOrientation:fromInterfaceOrientation

sorry for my poor English!
oh,I found the solution:
firstly , in RootViewController.mm changed
**- shouldAutorotateToInterfaceOrientation:interfaceOrientation {
return UIInterfaceOrientationIsPortrait||UIInterfaceOrientationIsLandscape ;
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead

  • supportedInterfaceOrientations{
    #ifdef __IPHONE_6_0
    return UIInterfaceOrientationMaskPortrait;
    #endif
    }**

secondly, in which scene the layer construct function add :
// if you want set Landscape
RollGate7::RollGate7
{
CCSize s = cocos2d::CCEGLView::sharedOpenGLView->getFrameSize;
if
{
cocos2d::CCEGLView::sharedOpenGLView->setFrameSize;
}
else
{
cocos2d::CCEGLView::sharedOpenGLView->setFrameSize;
}
cocos2d::CCEGLView::sharedOpenGLView->setDesignResolutionSize;
}

//or you want set Portrait
RollGate8::RollGate8
{
CCSize s = cocos2d::CCEGLView::sharedOpenGLView->getFrameSize;
if
{
cocos2d::CCEGLView::sharedOpenGLView->setFrameSize;
}
else
{
cocos2d::CCEGLView::sharedOpenGLView->setFrameSize;
}
cocos2d::CCEGLView::sharedOpenGLView->setDesignResolutionSize;
}

The solution is different for ios5 and ios6. This is my code to set device orientation to landscape only.

First, in RootViewController.mm:

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape( interfaceOrientation );
    }

  • (BOOL)shouldAutorotate
    {
    return YES;
    }

  • (NSUInteger)supportedInterfaceOrientations
    {
    return UIInterfaceOrientationMaskLandscape;
    }

  • (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
    return UIInterfaceOrientationLandscapeRight;
    }

Secondly, in AppController.mm:

use code below to set root view controller to window:
NSString **reqSysVer = `“6.0”;
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
    [window setRootViewController:viewController]; //iOS 6
} else {
    [window addSubview: viewController.view]; //iOS 5 or less
}

//    window.rootViewController = self.viewController;

and overwrite this function:

  • (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
    NSString *reqSysVer = `“6.0”;
    NSString**currSysVer = [[UIDevice currentDevice] systemVersion];

if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
{
return UIInterfaceOrientationMaskLandscape; //iOS 6
} else {
return UIInterfaceOrientationPortrait; //iOS 5 or less
}
}