0

I have an iOS Cocos2D app designed to run in landscape mode. When simulating the app on an iPhone 5 device, I use the following code to get the screen dimensions:

CGSize screenSizeInPixels = [CCDirector sharedDirector].winSizeInPixels; 

Execution of this code yields a screenSizeInPixels.width = 1136.0f and a screenSizeInPixels.height = 640.0f. But when I simulate/execute the same code in Xcode 6, I get just the opposite: a screenSizeInPixels.width = 640.0f and a screenSizeInPixels.height = 1136.0f.

Why are the pixel dimensions reversed?

JeffB6688
  • 3,782
  • 5
  • 38
  • 58
  • probably the same reason as always: it depends on when/where the first scene is launched and whether the app is a landscape or portrait app. Initially all apps launch in portrait mode before changing to landscape mode, at which point the size is changed to reflect that. – CodeSmile Sep 17 '14 at 17:01
  • @LearnCocos2D The app is a landscape app (i.e. the Device Orientation in Xcode is Landscape Left and Landscape Right). In the appDelegate, I first init the window and create the director. At that point, if I look at the winSizeInPixels, the width is 1136. Then I set the device orientation with [director setDeviceOrientation:kCCDeviceOrientationLandscapeRight]; At that point, If I look at winSizeInPixels, the width changes to 640. Nothing has changed in the code. This behavior is just the opposite in Xcode 5. I don't know if this is an iOS version issue or Xcode issue. How can I resolve this – JeffB6688 Sep 17 '14 at 18:47
  • possible duplicate? http://stackoverflow.com/questions/25777136/spritebuilder-project-with-wrong-node-positions-in-xcode-6/25777349#25777349 – Reza Shirazian Sep 17 '14 at 20:13

1 Answers1

0

This is a Bug in iOS SDK:

https://github.com/cocos2d/cocos2d-swift/issues/973

One Solution in that manually set the desired orientation in the info.plist, then everything seems to work ok. It works for me.

Nimisha Patel
  • 406
  • 5
  • 13
  • Not sure I understand your suggestion. info.plist already has an entry for Supported interface orientations. That is set when you choose the Device Orientation in the General Tab for the app target (i.e. same view where you set build settings, phases, etc.). For me, my desired orientation was Landscape (left home button). I can manually overwrite that value, but that essentially results in no change. Am I misunderstanding your suggestion? – JeffB6688 Sep 21 '14 at 13:52