Is it possible to detect device orientation change? Maybe thare are some functions like IsPortrait() or IsLandscape() or is it possible to register a callback function for orientation change? That would be great. I need this because I want to support both landscape and portrait modes in my simple app.
Can I find somewhere some kind of c*+ wrapper for common ios functionallity like in-app purchases and gamecenter? A c*+ class with functions like SendScore(char* leaderboard) or OpenLeaderboard(char* name) would be great If anyone has something like this please share
Ok I found a solution how to detect ios device orientation change and how to support both portrait and landscape resolution. In case someone needs this then this seems to be working with cocos2d-x 2.0.4 however this might not be the best solution :
changes in RootViewController.mm:
// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation ) || UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
return UIInterfaceOrientationMaskAll;
#endif
}
orientationDidChanged Notification will trigger only When Device is in Unlocked State(i.e Portrait Lock disabled) & Rotate Device to Landscape or Portrait.
If Device is in Portrait Locked then [[UIDevice currentDevice] orientation] will be always UIDeviceOrientationPortrait. If there is any changes in Device Orientation we won’t get any notification callback.
I have Used Accelerometer Value to Find out the Orientation.
That’s one way of doing it (sad that it comes down to that – I bet it rapidly ping pongs between orientations if it’s flat on the ground, easy fix is to threshold it).
When it is flat on the ground we can see changes in Orientation Value.
I have Taken Difference Between Acceleration Y & X Value and fixed it by using threshold value.