本文主要是介绍cocos2d 屏幕默认是横屏,修改为竖屏 的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在RootViewController.m文件里面,修改如下代码
的方法shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {//// There are 2 ways to support auto-rotation:// - The OpenGL / cocos2d way// - Faster, but doesn't rotate the UIKit objects// - The ViewController way// - A bit slower, but the UiKit objects are placed in the right place//#if GAME_AUTOROTATION==kGameAutorotationNone//// EAGLView won't be autorotated.// Since this method should return YES in at least 1 orientation, // we return YES only in the Portrait orientation//return ( interfaceOrientation == UIInterfaceOrientationPortrait );#elif GAME_AUTOROTATION==kGameAutorotationCCDirector//// EAGLView will be rotated by cocos2d//// Sample: Autorotate only in landscape mode//if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];}// Since this method should return YES in at least 1 orientation, // we return YES only in the Portrait orientationreturn ( interfaceOrientation == UIInterfaceOrientationPortrait );#elif GAME_AUTOROTATION == kGameAutorotationUIViewController//// EAGLView will be rotated by the UIViewController//// Sample: Autorotate only in landscpe mode//// return YES for the supported orientations// 横屏//return ( UIInterfaceOrientationIsLandscape( interfaceOrientation ) );return ( UIInterfaceOrientationIsPortrait( interfaceOrientation ) );//坚屏#else
#error Unknown value in GAME_AUTOROTATION#endif // GAME_AUTOROTATION// Shold not happenreturn NO;
}
//
// There are 2 ways to support auto-rotation:
// - The OpenGL / cocos2d way
// - Faster, but doesn't rotate the UIKit objects
// - The ViewController way
// - A bit slower, but the UiKit objects are placed in the right place
//
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will be rotated by cocos2d
//
// Sample: Autorotate only in landscape mode
//
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else
这篇关于cocos2d 屏幕默认是横屏,修改为竖屏 的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!