user5691928
user5691928

Reputation:

Cocos 2dx Portrait Mode Object Locations are messed up

I tried making a game in cocos 2dx. It is working perfectly fine in landscape mode. I even checked it on various devices. But when I switch to portrait mode the sprites and nodes in every scene are in different positions and some aren't even visible. I am setting everything relative to the screen width and height. For example:

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

Plus to change to portrait mode, on Xcode, I clicked on the project name, went to the general tab and changed from Landscape Left and Landscape right to Portrait. When I tried to change to portrait mode in the method in the cocos.org page basically editing RootViewController.mm by replacing

return UIInterfaceOrientationMaskAllButUpsideDown;

with

return UIInterfaceOrientationMaskPortrait;

the Xcode simulator still crashed and gave me this error

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

Upvotes: 0

Views: 72

Answers (1)

Makalele
Makalele

Reputation: 7531

I have an application in portrait mode.

1) in general settings you need to uncheck landscape and leave portrait only.

2) in info.plist "Supported interface orientations" you have to have Portrait (bottom home button).

3) in AppController.mm in supportedInterfaceOrientationsForWindow return just UIInterfaceOrientationMaskPortrait.

4) also in AppDelegate.cpp in applicationDidFinishLaunching: remember to use setDesignResolutionSize with portrait dimensions, for example 960x640.

Upvotes: 0

Related Questions