nativeInit called with wrong screensize when running on device with software android buttons

nativeInit called with wrong screensize when running on device with software android buttons
0.0 0


Hi again! Time for more fun with archos tablets :slight_smile:

The archos 101 doesn’t have the usual 4 hardware buttons common on android devices (back, search, home & options). Instead, there are software buttons that appear on the side of the screen, as you see here:

However, nativeInit is called with screen values that are reported from getWindowManager().getDefaultDisplay().getMetrics(dm). These are the total size of the screen, and include the software buttons. However, the Cocos2dxGLSurfaceView is automatically initialised by the SDK, and reports different values to those from the windowmanager. If the nativeInit is called with the windowmanager values, the cocos2d-x app becomes cropped, with the software buttons squeezing out about 100 pixels.

Anyway, the following code added to fixes this problem:

protected void onSizeChanged (int w, int h, int oldw, int oldh)
Cocos2dxActivity.screenWidth = w;
Cocos2dxActivity.screenHeight = h;

This function is called before nativeInit, so overriding the activity’s recorded screen values allows the correct values to be passed to nativeInit. However, this might not be the most robust fix. At least, removing the initial call to getMetics is probably acceptable.


ha, a bit odd, software key on android device. It’s the first time I see this design.
Thanks for sharing your experience!


Hi again,

So I started testing a game on an android 3.0 device, and ran into the same problem. I guess the standard for 3.0 is to have no hardware buttons, and instead a system UI bar at the bottom at all times. I don’t have a hardware device, but you should be able to see this behaviour in the 3.0 emulator. The above fix still works, though.


Yes, we have found it.
#743 is created for it.

Thank you.


I see similar problem on Samsung Galaxy Tab 10.1 with Android 3.1.

In main cases I got resolution 1280x752 (its resolution without bottom softbutton bar), but sometimes I got resolution 1280x800.

In second case is top part of screen outside of display and touches position are shifted. I didnt catch conditions, where this happend.