Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / agk::GetScreenBounds weird behaviour

Author
Message
east
13
Years of Service
User Offline
Joined: 4th Apr 2013
Location:
Posted: 4th Dec 2013 06:43 Edited at: 4th Dec 2013 11:06
I'm developing for android in Tier 2 and i'm using agk::SetScissor(0,0,0,0) to remove the black bar and i'm using agk::GetScreenBounds (Left, Right, Top, etc) to get the screen bounds. My device is Samsung Galaxy Note with screen resolution 1280x800 and I set my virtual resolution at 960x640.

The expected return value for GetScreenBounds is Left: -32, Right: 992, Top: 0, Bottom: 640 but to my surprise, the returned value is Left: 0, Right: 960, Top: -448, Bottom: 1088. This is only happened on the app:Begin function, if i called those GetScreenBounds function after the begin function (in app:Loop) it works as expected.

It seems at the app::begin function the device is still on the potrait mode and the GetScreenBounds functions assume the device is still on potrait mode while i have already called agk::SetOrientationAllowed(0,0,1,1) at the begining of the begin function.

Is there a way for the GetScreenBounds functions to return the expected value at the Begin function? I prefer to call those functions once and save them to my variable rather than calling them every loop.
Ancient Lady
Valued Member
22
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Dec 2013 15:22 Edited at: 4th Dec 2013 15:23
Quote: "Is there a way for the GetScreenBounds functions to return the expected value at the Begin function?"

Since you are working in Tier 2, there is a command, OrientationChanged, that you can use in app::Begin() that forces the orientation change. That then makes a lot of the rest of the display information in the system get properly initialised.

This is a cut down version of the code in a function called from app::Begin() (it has only the bits relevant to the display orientation and determining the extra space above/below or left/right, I combined code from the actual function and the method called in a class object used to handle display stuff) (any variables used that aren't defined in the method are global/static ones):


You also want to make sure that your Xcode project has only the two landscape modes allowed for both iPad and iPhone.

And, there are some lines to add to the <project>-Info.plist that also make the app start in landscape mode (you can only pick one to start in):


Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
east
13
Years of Service
User Offline
Joined: 4th Apr 2013
Location:
Posted: 4th Dec 2013 20:19
Thanks for your respons Ancient Lady but my project is an Android Tier 2 Project.

So I tried the OrientationChanged command with my android device but it didn't work. So I think I should change some project setting like what you did on IOS. I opened the manifest.xml file and found about android:screenOrientation and change the value from "FullSensor" to "sensorLandscape" and it works!! The GetScreenBounds functions now has returned the expected value.

Thanks for your help
Ancient Lady
Valued Member
22
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Dec 2013 20:49
Okay, I somehow thought it was an Xcode project. No problem.

And you found exactly the solution I was going to point you to.

You can also use 'reverseLandscape' (iOS Left Landscape) or 'Landscape' to force one or the other and it helps keep Android happy not trying to flip orientation.

Someone told me that the android:screenOrientation only needs to be in the main activity. But putting the line in every '<activity' or '<activity>' section doesn't hurt and it makes sure that everything is on the same page, so to speak.

Good luck with your app and Happy Programming!

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2026-07-17 17:13:14
Your offset time is: 2026-07-17 17:13:14