在cocos2D 1.0版後,使用HELLOWORLD的範本,會使用UIViewController。
這時候,一些語法就不適用了。
不用UIViewController的時候:
在AppDelegate.m中,找到if GAME_AUTOROTATION == kGameAutorotationUIViewController,並且註解掉----
/*橫向判斷消除
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif
*/
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
Director有加入UIViewController的時候:
請在RootViewController.m內的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation中,把所有內容註解掉,基本上最後應該會變成:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
如果要讓特定的CCLayer Object做橫轉直的旋轉,還另有解法:(來源 如何让cocos2d支持横竖屏切换
// 添加侦听器
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
// 设置cocos2d方向
-(void) orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {//支持的屏幕方向
[[CCDirector sharedDirector] setDeviceOrientation:(ccDeviceOrientation)orientation];
}
}
沒有留言:
張貼留言
歡迎大家留言提問,我會答的都會盡力回答!
如果太久沒出現回應就是我又忘記回來看留言了TAT