Cocos 2dx纵向模式对象位置搞砸了

时间:2016-02-05 02:34:15

标签: c++ cocos2d-x

我尝试在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

1 个答案:

答案 0 :(得分:1)

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

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

2)在info.plist"支持的界面方向"你必须有肖像(底部主页按钮)。

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

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