English 中文(简体)
可可2d游戏取向
原标题:Cocos2d game orientation switching left->right->left directly after launch

I m using the default cocos2d template with slight modification to the base code.

My game is played on left or right only- no portrait.

When the game launches, it starts right, then flips upside-down, then flips right again.
I looked through several posts on the issue and cannot seem to put my finger on what s making the interface flip back and forth without the device being moved.
Appreciate any help!

I have the following related code:

RootViewController.m:

#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

Game:

#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
问题回答

我今天也存在同样的问题,似乎到了我的申请名单上支持的方向。 app子在地貌上发射,右翼飞去,然后真正地迅速消失。

我在“Summary”表格中(在座各位支持方向、电灯、发射图像等)进入了我的项目特性,并选择了所有支持的方向。

I then ticked them again in order (Landscape Right, Landscape Left) - and verified in the "Info" tab that they were in this order in the array, under the "Supported Interface Orientations" section.

Item 0 - Landscape (right home button) Item 1 - Landscape (left home button)

Not had the problem since, hope this helps.





相关问题
Cocos2d - Shooting Game Problem

everyone, I made a shooting game just like 1942(classic shooting game),but here s the question, FPS drops to 5~6 when the fighter shoot out a straight line of bullet,about 7~8 bullets in the screen,...

AtlasSpriteManager animation

I am using AtlasSpriteManager and AltasSprite to create frame by fram animation with 1 one file. I wanna write something that at first show a simple picture, without any animation and for example when ...

background moves together with image

I have 4 images and a background. I already about to animate the image to move accordingly. But the back ground is not moving. I am not sure how to make the background move accordingly to the movement ...

NSMutable array invalid after objectAtIndex

@implementation Level @synthesize doors, rooms; - (id) init { self = [super init]; if (self != nil) { rooms = [[NSMutableArray alloc] init]; doors = [[NSMutableArray alloc] init]; ...

How to subclass AtlasSpriteManager in Cocos2d?

I need to create some compound sprites that will all move and rotate together. Since it s possible to change the position and rotation of an AtlasSpriteManager I ve been trying to subclass so I can ...

热门标签