I am using Batch framework to integrate Push notification into my game.
Everything is fine with iOS.
In Android it works fine but i have one bug.
If device is locked when push notification comes on that time game launched with width/height swapped.
my mobile res is 1920 x 1080 and my game is in landscape mode
Below method is called twice in Cocos2dxGLSurfaceView.java
protected void onSizeChanged( ... )
first with width : 1080 height : 1920
second width : 1920 height : 1080
So game is starting with first config, but it should start with second.
Any thoughts, any help?
BTW Batch officially doesn’t support cocos2d-x so there are not helping, but i am still using it as its free and easy to integrate.
So i modified onSizeChanged method in Cocos2dxGLSurfaceView.java as below
Note: Do this if your game is in landscape mode.
@Override
protected void onSizeChanged(final int pNewSurfaceWidth, final int pNewSurfaceHeight, final int pOldSurfaceWidth, final int pOldSurfaceHeight) {
if(!this.isInEditMode()) {
if(pNewSurfaceWidth < pNewSurfaceHeight)
this.mCocos2dxRenderer.setScreenWidthAndHeight(pNewSurfaceHeight, pNewSurfaceWidth);
else
this.mCocos2dxRenderer.setScreenWidthAndHeight(pNewSurfaceWidth, pNewSurfaceHeight);
}
}
You have to modify file outside project - after cocos2d-x update you can forget changing it.
Solution: do not forget
There’s no way to determine in this place in code if game is landscape or portrait. I have many projects, which import this one. Some are landscape, other portrait.
Solution: make 2 projects landscape or portrait
Worst issue: I have virtual navigation buttons on my screen. So first time (when launching from locked screen, so bug should appear) I can see in logs:
06-30 15:34:21.090: I/System.out(1375): onSizeChanged, from: 0, 0, to: 1080, 1920
And game is initializing even after correcting width and height in 1920x1080 resolution, but this is incorrect and I can see virtual navigation keys overlapping part of the game.
Just a second later I can see second call:
06-30 15:34:21.970: I/System.out(1375): onSizeChanged, from: 1080, 1920, to: 1794, 1080
but it’s too late, game is already created in wrong resolution. It should somehow refresh.
If I normally run the game I can see from: 0, 0 to 1794, 1080 and in this situation everything is ok.
Also you have reproduce it another way: rotate your phone to portrait, tap app to run it and immediately lock screen. Before it’ll launch it won’t have time to rotate and bug will appear.
Solution: game should reinitialize after changing orientation?
That’s strange, because it should run always in landscape from the start:
android:screenOrientation=“landscape”
this I can find in my manifest file associated with org.cocos2dx.cpp.AppActivity.
Well i dont have this issue.
And i am not using virtual navigation so i dont have any other issue as of now.
But yes indeed, game should reinitialize after changing orientation