我使用默認的cocos2d模板稍作修改的基本代碼。
我的遊戲只在左側或右側播放 - 沒有人像。
當遊戲啓動時,它啓動正確,然後翻轉顛倒,然後再次翻轉。
我翻看了關於該問題的幾篇文章,似乎無法將我的手指放在讓界面翻轉而不移動設備的東西上。
感謝任何幫助!
我有以下相關代碼:
RootViewController.m:
Cocos2d遊戲的方向切換左 - >右 - >左啓動後直接
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGRect rect = CGRectZero;
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
rect = screenRect;
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
rect.size = CGSizeMake(screenRect.size.height, screenRect.size.width);
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [director openGLView];
float contentScaleFactor = [director contentScaleFactor];
if(contentScaleFactor != 1) {
rect.size.width *= contentScaleFactor;
rect.size.height *= contentScaleFactor;
}
glView.frame = rect;
}
#endif
的AppDelegate:
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
#endif
GameConfig.h:
#define kGameAutorotationNone 0
#define kGameAutorotationCCDirector 1
#define kGameAutorotationUIViewController 2
#if defined(__ARM_NEON__) || TARGET_IPHONE_SIMULATOR
#define GAME_AUTOROTATION kGameAutorotationUIViewController
#elif __arm__
#define GAME_AUTOROTATION kGameAutorotationNone
請重新發布不含HTML格式的代碼,目前它無法讀取。 – LearnCocos2D 2012-01-14 15:22:54