【问题标题】:Cocos 2dx Portrait Mode Object Locations are messed upCocos2d 纵向模式对象位置混乱
【发布时间】:2016-02-05 02:34:15
【问题描述】:

我尝试在 cocos 2dx 中制作游戏。它在横向模式下工作得很好。我什至在各种设备上检查过它。但是当我切换到纵向模式时,每个场景中的精灵和节点都处于不同的位置,有些甚至不可见。我正在设置与屏幕宽度和高度相关的所有内容。例如:

 backgroundSprite->setPosition(Point(visibleSize.width/2 +origin.x , visibleSize.height/2 +origin.y));

加上要更改为纵向模式,在 Xcode 上,我单击项目名称,转到常规选项卡并将横向左侧和横向右侧更改为纵向。当我尝试在 cocos.org 页面中的方法中更改为纵向模式时,基本上通过替换来编辑 RootViewController.mm

return UIInterfaceOrientationMaskAllButUpsideDown;

return UIInterfaceOrientationMaskPortrait;

Xcode 模拟器仍然崩溃并给了我这个错误

2016-02-05 07:59:25.490 CircleGame-mobile[3192:39201] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and [RootViewController shouldAutorotate] is returning YES'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000110116e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010fae8deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000110116d9d +[NSException raise:format:] + 205
    3   UIKit                               0x000000010db8f52b -[UIViewController __supportedInterfaceOrientations] + 903
    4   UIKit                               0x000000010db7dcd7 -[UIViewController _preferredInterfaceOrientationGivenStatusBarAndDeviceAndOrientation:] + 90
    5   UIKit                               0x000000010da4854c -[UIWindow setRootViewController:] + 111
    6   CircleGame-mobile                   0x000000010c3d8563 -[AppController application:didFinishLaunchingWithOptions:] + 883
    7   UIKit                               0x000000010d9d11f1 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
    8   UIKit                               0x000000010d9d2397 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
    9   UIKit                               0x000000010d9d8cc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
    10  UIKit                               0x000000010d9d5e7b -[UIApplication workspaceDidEndTransaction:] + 188
    11  FrontBoardServices                  0x0000000112673754 -[FBSSerialQueue _performNext] + 192
    12  FrontBoardServices                  0x0000000112673ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    13  CoreFoundation                      0x0000000110042a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    14  CoreFoundation                      0x000000011003895c __CFRunLoopDoSources0 + 556
    15  CoreFoundation                      0x0000000110037e13 __CFRunLoopRun + 867
    16  CoreFoundation                      0x0000000110037828 CFRunLoopRunSpecific + 488
    17  UIKit                               0x000000010d9d57cd -[UIApplication _run] + 402
    18  UIKit                               0x000000010d9da610 UIApplicationMain + 171
    19  CircleGame-mobile                   0x000000010c3ec934 main + 100
    20  libdyld.dylib                       0x00000001105fa92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

【问题讨论】:

    标签: c++ cocos2d-x


    【解决方案1】:

    我有一个纵向模式的应用程序。

    1) 在一般设置中,您需要取消选中横向并仅保留纵向。

    2) 在 info.plist “支持的界面方向”中,您必须有 Portrait(底部主页按钮)。

    3) 在supportedInterfaceOrientationsForWindow 中的AppController.mm 中只返回UIInterfaceOrientationMaskPortrait。

    4) 也在 AppDelegate.cpp 中的 applicationDidFinishLaunching 中: 记得使用纵向尺寸的 setDesignResolutionSize,例如 960x640。

    【讨论】:

    • 它仍然无法正常工作。我尝试了您所做的更改,但我编辑的是 RootViewControler.mm 而不是 AppController.mm。错误不再出现,但对象仍未对齐
    • 它应该可以工作,因为我是从一个纵向制作的游戏中得到它们的。那么,你如何加载你的场景呢?你是从 Cocos Studio 加载它还是从代码中加载所有内容?你应该先在空白项目上尝试一下,然后复制第一个场景,你应该能够找出问题所在。
    • 我按照您说的做了,并意识到了问题所在。我的父容器存在对齐问题。谢谢你。我工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    相关资源
    最近更新 更多