cocos2d屏幕方向问题

发布于 2024-10-02 07:08:11 字数 142 浏览 2 评论 0原文

我使用 cocos2d 0.99-rc0 中存在的标准旋转代码来支持纵向 + 两种横向模式。我以纵向模式显示菜单,然后屏幕旋转到横向以进行实际游戏。问题是,当我返回纵向时,整个主菜单场景偏离了屏幕的一半,就像有人移动了锚点或其他东西一样。

有什么想法吗?

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 portrait, the whole mainmenu scene is off by half the screen, like someone had moved the anchor point or something.

Any ideas please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中性美 2024-10-09 07:08:11

一个可能的简单解决方案是在场景开始时应用方向,然后重新应用菜单项的位置,使其全部对齐。

我执行以下操作来更改屏幕方向:

首先,第一行进入 init 方法内部,我设置一个计时器在 0.5 秒后快速启动。将其放入计时器意味着在我的游戏中,场景转换(淡入淡出)可以顺利进行,屏幕不会旋转/快速旋转,但您可能不需要使用它。

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

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

关键行如下,您不一定需要计时器:

[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];

当然您可以针对不同的方向更改此位:

CCDeviceOrientationLandscapeLeft
CCDeviceOrientationLandscapeRight
CCDeviceOrientationPortrait
CCDeviceOrientationPortraitUpsideDown

祝您好运。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文