开发者

cocos2d screen orientation problems

I am using the standard rotation code present in cocos2d 0.99-rc0 to support portrait + two landscape modes. I am showing the menu in portrait mode, and then the screen rotates to landscape for the actual game. Problem is that when i go back to portrai开发者_如何学Ct, the whole mainmenu scene is off by half the screen, like someone had moved the anchor point or something.

Any ideas please?


A possible simple solution would be to apply the orientation at the start of the scene then after wards re-apply the positions of your menu items so that its all aligned.

I do the following to change the screen orientation:

Firstly, the first line goes inside the init method I set a timer to start after a quick 0.5 seconds. Putting it in a timer means in my game the scene transition (fade) works smoothly, the screen doesn't rotate/snap round then, but you probably won't need to use this.

[self schedule:@selector(rotate:) interval:0.5];

-(void)rotate:(ccTime) dt{
    [[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
    [self unschedule:@selector(rotate:)];
}

The key line is below, you don't necessarily need the timer:

[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

Of course you can alter this bit for different orientations:

CCDeviceOrientationLandscapeLeft
CCDeviceOrientationLandscapeRight
CCDeviceOrientationPortrait
CCDeviceOrientationPortraitUpsideDown

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜