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.

Newcomers AppGameKit Corner / Question on determining device screen and height

Author
Message
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 22nd Jul 2015 10:28
Hello-

The documentation seems to imply that GetDeviceHeight() and GetDeviceWidth() will return the same values regardless if I change the device from landscape to portrait, and vice-versa. Is this correct?

Whether that is true or not, I'm having trouble with these commands and my Asus tablet. In landscape mode, the device dimensions are 1024 x 552. In portrait mode, the dimensions are 600 x 976. The problem I have with the Get() commands is that even if I force landscape orientation, the portrait dimensions are returned unless the device was already in landscape mode before I launch the application.

I had thought to get around this by using this code:

However, there is a bug there. Trying to force the device into landscape mode causes the loop to exit even if the device is not physically in that mode. So I think that Set() is interfering with the correct operation of Get(). I would expect Get() to always return the physical setup of the device, and if I want to separately confirm what orientations I *should* be using, that would be a different function.

I'm also running into trouble testing on a Windows PC when I need to check for orientations. Is there a way to detect if the code is running on a PC so I can skip such checks?

Goo Goo G'Joob!
theUsual
9
Years of Service
User Offline
Joined: 13th Jul 2015
Location: Norway
Posted: 23rd Jul 2015 01:01
Could you post a snippet of the settings you are using regarding the screen? SetAspectRatio, SetVirtualResolution, etc.

I've noticed that if I do "SetOrientationAllowed( 1, 1, 0, 0 )" (which is portrait), while my AppGameKit 2 Player is in landscape, the orientation won't do as it's told.

My last app involved using GetDeviceWidth/Height and everything looked the same even though the screen sizes wasn't the same. When you build an .apk (if you're building for android), you specify the orientation there too, and it will force the app into the selected orientation regardless if the device is in the other orientation or not.

I don't know the technicality behind AppGameKit, but maybe DeviceWidth/Heigth and Orientation isn't supported for windows, even though it's a tablet. Just tested, and GetDeviceWidth/Heigth displays the same width/height you specify manually. If you set the screen size to 1024x1024, and then later change it to DeviceWidth/Heigth for a more flexible solution for a smartphone/tablet, the windows computer still displays the windows as 1024x1024. At least it does in my case.
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 23rd Jul 2015 08:06
This is the opening code of my project (the working version):

If I invoke SetOrientationAllowed() while the device is still in portrait mode, GetOrientation() will fail to return the correct value based on the actual physical status of the tablet. Likewise GetDeviceWidth/Height() will also return the portrait dimensions even if the device is physically in landscape mode at the time the function is called. So everything goes wrong unless I lock the application in landscape mode well after the device is physically aligned that way.

Note that I added GetPointerPressed() only to facilitate debugging on my desktop PC, since it is impossible to rotate the desktop. I've also noticed that the desktop PC version of the application starts out thinking it is portrait mode even if it was created with a greater width than height.

Goo Goo G'Joob!
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 29th Jul 2015 00:50 Edited at: 29th Jul 2015 00:50
I find GetDeviceHeight() and GetDeviceWidth() to be a little flaky - more to do with all the various devices than anything else I suspect.

I generally use the following code to sort out dealing with the screen:



This is taken from my game Invaders of the 29th Dimension (see the link in my signature).

This will obviously mean that the player will have to rotate their device if needed. But it doesn't matter if the actual screen resolution of the device is different from the virtual resolution, AppGameKit simply scales it to fit but you can end up with black borders which is why I get the screen bounds and then use SetScissors().

Is there any reason that the player has to have to device held correctly before the app can continue?

Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
Eqqman
9
Years of Service
User Offline
Joined: 15th Jul 2015
Location:
Posted: 30th Jul 2015 09:26
Quote: "Is there any reason that the player has to have to device held correctly before the app can continue?"

Yes, because if the device dimensions have been incorrectly loaded then the graphics won't be drawn correctly, as I use those parameters to figure out how big to draw objects and where to place them.

Goo Goo G'Joob!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 2nd Aug 2015 00:57
There is a command available in Tier 2 that would really help this situation if it were available in Tier 1: agk:rientationChanged(4)

This command can be used in setup and it forces the application to the orientation that you want it to be at.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-21 20:32:43
Your offset time is: 2024-11-21 20:32:43