iOS6 breaks default autorotation and landscape in cocos2d 1.0 beta - iphone

In the default cocos2d 1.0 beta template, AppDelegate.m has some code:
// AppDelegate.m
// IMPORTANT:
// By default, this template only supports Landscape orientations.
// Edit the RootViewController.m file to edit the supported orientations.
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation: kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
#endif
Next, In GameConfig.h, we have defined:
// GameConfig.h
#define kGameAutorotationNone 0
#define kGameAutorotationCCDirector 1
#define kGameAutorotationUIViewController 2
//
// Define here the type of autorotation that you want for your game
#define GAME_AUTOROTATION kGameAutorotationUIViewController
Together, this was working to produce a landscape setup that auto-rotated to either landscape-left or landscape-right depending on how you held the device. TableViews autorotated as well (I have several tables placed on top of some cocos2d CCScenes).
However...I updated to iOS6 last night. As well as XCode 4.5.
I'm hoping it's not just me, but my app's rotation is completely broken now. I'm trying to fix it via code for at least one tableview...changing GAME_AUTOROTATION seems to have no affect on tableviews, just the cocos2d CCScenes (which is half of the solution in a way).
I may just start from scratch and get something built up instead of working with pre-written code, this is just mega-frustrating!! Thanks a lot, Apple!

My partial solution is
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
//[director setDeviceOrientation:kCCDeviceOrientationPortrait];
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
Do you have a better solution?
Thanks

The answer was to upgrade my stuff to cocos2d 2.0 and to remove the dependency on the RootViewController, which is no longer used.
navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
[window_ setRootViewController:navController_];

Related

convert game from portrait mode to landscape mode

I am new to cocos2d game developing. Here, my game is developed in portrait mode. I just want to convert landscape mode. and tell me which method is used instead of shouldAutorotateToInterfaceOrientation method because this method is not available in iOS 6?
My whole game is developed portrait mode from the start.
Thank you in advance.
you will find below code in appdelegate.mm file
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
change it to.
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
let me know it is working or not!!!!
Not sure this will solve your problem, but as you mentioned How to handle orientation in OS6, I would like to give you the code what I am using for Handling Device Orientation in iOS 6 and iO5 etc.
So here is the code snip, where you can decide what orientation support you want in your app
Handle Screen Orientations in iOS 5 and iOS 6
//For up-to iOS 5.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported all orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
//For iOS 6.0
-(NSInteger)supportedInterfaceOrientations
{
//Supporting only portrait orientation.
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return NO;
}
Reference
Hope this will help you!!
Go to target and set supported interface orientation.

Cocos 2d 2.0 shouldAutorotate not working?

I'm having some issues. I have a cocos2d game I'm just about done developing. However I've run into a problem where I need to enable portrait orientation in my apps plist for game center sign in to work without throwing a SIGABRT error. So once I enable that from my app's build summary page (Or add it to the info.plist file as a supported orientation) it works fine. But then anytime in my game if you turn the iPhone it will flip to portrait mode if it senses you turned it that way. I've tried messing with the shouldAutorotateToInterfaceOrientation method from my AppDelegate.m and it's not getting called AT ALL, not at any time is it being called. I threw an NSLog statement in the method to be sure if it's being called, and it's not.
So, basically my real issue is. I need my game to STAY in landscape mode BESIDES when the Game Center login screen pops up. How do I do this in a Cocos2d 2.0 game?
I'm am using iOS6
First, make sure that the app supports portrait and landscape orientations in the target summary.
Then you'll need to make a new root view controller that forces you into landscape mode so that your game doesn't start rotating strangely:
#implementation CUSTOM_RootViewController
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate {
return YES;
}
#end
Finally, in the AppDelegate.m file, replace the original navigation controller with your new one:
// Create a Navigation Controller with the Director
//navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
navController_ = [[SMD_RootViewController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
Now you should be able to overlay a portrait view on top.
Hope this helps!
Use this code in AppDelegate.mm
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_6_0
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskLandscape;
}
#else
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
#endif
In IOs6 shouldAutorotateToInterfaceOrientation method not worked, so u change in appDelegate .m file [window addSubview:viewcontroller] to [window setRootviewcontroller:viewcontroller] after its works fine.

MPMoviePlayerViewController not playing in Landscape orientation under 5.1

Has anything changed in 5.1 which would affect how a MPMoviePlayerViewController works regarding device orientation?
I started getting reports from users today that videos were playing only in portrait mode. I figured out that they were using 5.1 and I quickly upgraded a device to recreate the situation. My code has not changed and works perfectly in 4.x, 5.0, and 5.01.
All the views in my app display in portrait mode except when a user clicks on a video, the movie player is suppose to take over the whole screen and launch into landscape more. The app using the 5.0 SDK but targeting 4.0. Here is the code I am using to display a video:
VideoPlayer *vp = [[VideoPlayer alloc] initWithContentURL:movieURL];
vp.moviePlayer.movieSourceType = src;
vp.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
vp.moviePlayer.shouldAutoplay = TRUE;
[self presentMoviePlayerViewControllerAnimated:vp];
VideoPlayer is a subclass of MPMoviePlayerViewController where the shouldAutorotateToInterfaceOrientation is overridden like so:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIDeviceOrientationLandscapeLeft);
}
This pattern is recommended all over the internet and even by Apple. I don't understand why its not working under iOS 5.1 or why more people aren't complaining about this.
Any help will be greatly appreciated.
I had the same problem also - i was playing the movie on a opengl subview, (im making an interactive ebook in landscape mode so needed my movie - (in a uiview) to play in landscape also)
I corrected this by:
subclassing the open glview to a *viewcontroller then linking that *viewcontroller to the window
So while working with cocos2d i can now use all uikit in the correct orientation.
Sending all uikit views to my subclasses opengl view. (while making sure to add in my app delegate and checking that orientation is stated in plist too.)
"#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
"#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
"#endif
hope this helps someone :) im very new at cocos2d so it took a while to figure out what i was doing wrong.
I had the same issue in iOS 5. The only way I was able to get it to work was to subclass MPMoviePlayerViewController.
#implementation MovieViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
} else {
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
}
#end
It looks you have already tried to do this, but this block of code is working for me on the device with iOS 5.1. Not sure about the simulator.
I had a bunch of orientation issues after upgrading to iOS 5.1. For me, it was because the allowed orientations of sibling viewcontrollers up the chain resulted in no allowable orientation for a modal controller I was adding.
Do you have any cases in your view hierarchy where two subviews are added to a view? I was adding two subviews to my window in applicationDidFinishLaunching, and before iOS 5.1, they could have independent allowable orientations. ie, I could have one fixed in portrait orientation while the one on top rotated. Now, the other subview insists on portrait orientation.
My solution was to force the non-rotating view below:
[self.window insertSubview:self.nonRotatingViewController.view belowSubview:self.rotatingViewController.view];
This post helped me figure that out (and has some code):
iOS: Disable Autorotation for a Subview

Cocos2d portrait mode not working on iPhone

I'm building a cocos2d game which is supposed to be in portrait mode. I changed the RootViewController.m to portrait mode:
return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );
Everything works fine, both on the simulator and on my iPad. However, when I run the game on my iPhone, it defaults back to landscape mode.
Any ideas on how to fix this?
Thanks.
in ur app delegate.. Put this line:
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
after
[director setAnimationInterval:1.0/30];
[director setDisplayFPS:YES];

Cocos2d - Setting Device/Screen Orientation

I am new to the cocos2d API and have noticed that there are a few ways to set the screens orientation within the templates. I have not been able to figure out the correct way to set my orientation to LandscapeRight and keep it that way throughout the entire game. How do I change my orientation so that it maintains LandscapeRight? Any help is appreciated. Thank you!
The answer here has changed with cocos2d 2.0, as CCDirector is now a ViewController on iOS:
CCDirector no longer supports device orientation. All autorotation and
device orientation is handled by RootViewController now. Fortunately,
[[UIDevice currentDevice] orientation] can be used in place of
[[CCDirector sharedDirector] deviceOrientation]. The enums are the
same, except that they begin with UI instead of CC.
Forcing a specific orientation is a simple matter of returning YES
only to the desired orientation in the RootViewController method
shouldAutorotateToInterfaceOrientation.
Choosing between Cocos2D v1.x & 2.x and Tips for updating to Cocos2D 2.0 at learn-cocos2d.com
Modify GameConfig.h from the cocos2d template.
#define GAME_AUTOROTATION kGameAutorotationNone
/* original code is kGameAutorotationUIViewController. */
And modify AppDelegate.m as well.
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
/* original code is "Left". */
#endif
Use this line:
[[CCDirector sharedDirector] setDeviceOrientation:kkCCDeviceOrientationLandscapeRight];
In the RootViewController.m,search for the line
return ( UIInterfaceOrientationIsPortrait(interfaceOrientation ));
change it to
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation ));
if you added shouldAutorotateToInterfaceOrientation and not solved your problem
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
THEN
Try to add this line to appDelegate.m
[window_ setRootViewController:navController_];
Good Luck
The correct answer - took me a while to find - is in the info.plist, change the supported interface orientations values, item 0 and item 1 have 4 possible values, Portrait (top home button) etc.