0

I put my profile in landscape:

<activity
    android:name="org.cocos2dx.cpp.AppActivity"
    android:screenOrientation="landscape"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Then I start my game and print the origin and the visible size.

log("DEBUG: origin = %f, %f", origin.x, origin.y);
log("DEBUG: visibleSize = %f, %f", visibleSize.width, visibleSize.height);

The output was: (BTW, the design resolution was 1024 x 768)

D/cocos2d-x debug info: DEBUG: origin = 0.000000, 75.772583
D/cocos2d-x debug info: DEBUG: visibleSize = 1024.000000, 616.454834

Notice that the "back-home-apps" system bar is on the right side of the screen. I also tried to put the image to the middle of the screen by setting it's position to be (origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2), but as you can see, because of the wrong visible size and origin, the image is towards the lower part of the screen.

enter image description here

I was expecting that the origin should be (0,0) and the visible size should be (1024 - height-of-system-bar) x 768. But as you can see the origin has a delta on Y axis, and the visible size take a hit also on Y axis --- as if Cocos2d-x thought that the screen was in portrait orientation and the system bar is at the bottom of the screen.

How do I tell cocos2d that the phone is in landscape orientation?

Roy
  • 880
  • 1
  • 12
  • 27

1 Answers1

0

Solved the puzzle. Two things here:

  1. I was wrongly calculating the coordinates. What I actually did was ((origin.x + visibleSize.width / 2), (origin.y + visibleSize.height / 2)). I made the mistake of typing into this question rather than copy/pasting the code, thus the confusion.

  2. After this fix, the origin and visible size still are not the screen size, and this is caused by me using the NO_BORDER policy (which I failed to mention in the question). Cocos2d enlarged the content to fill all the screen space, causing the axis which is longer than necessary to be clamped in the middle.

Roy
  • 880
  • 1
  • 12
  • 27