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 / Floating layout for different aspect ratios

Author
Message
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 31st May 2017 13:44
Hey there,

I have a question regarding different aspect ratios for mobile devices. We all now we have everything from 4:3 (iPad) up to 16:9.
Usually I use a 16:9 background which always start at the top left position and is just cropped for lower aspect ratios to avoid black borders.

So here's an example. You see I set a 16:9 window size but a 4:3 virtual resolution as this is the minimum view area that is available over all possible devices.

The code below works fine I just want to ask if this is the right way of doing it by using SetViewOffset and then paint everything normally?

Attachments

Login to view attachments
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 1st Jun 2017 23:58
Hey Xaron,

SetWindowSize doesn't have any effect on mobile devices, just on Windows / Mac

SetViewOffset is rather used for scrolling through a level or stuff like that. If you plan on using it your way, I wouldn't put it in the main loop.

With SetScissor, there are no black borders, so drawing your 16:9 background at negative values on a 4:3 mobile device should do the trick.
I think a good way would be to find out the aspect ratio of the device and draw your gfx accordingly.

I only have experience with the AppGameKit percentage system yet, but I'll be using the virtual resolution for my next game, so I'll have to deal with this problem soon, too


PSY LABS Games
Coders don't die, they just gosub without return
easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 2nd Jun 2017 03:37
Hey Xaron,

There are two ways in AppGameKit to draw to the entire screen on mobile. Either use the percentage system (which I don't recommend), or call SetScissor(0,0,0,0) which will allow your to draw to the entire screen regardless of the screen size.

Once you call SetScissor(0,0,0,0), you should call SetVirtualResolution( 100, 100) and SetOrientationAllowed( 1, 1, 0, 0 ) (for portrait, invert those bits for landscape). This will basically set your default drawing area to a square box in the centre of the screen and give it a virtual resolution of 100x100. This means if you call SetSpritePosition(ID,0,0), it will place the sprite somewhere on the middle left part of the screen (the top left of that box). However since we called SetScissor(0,0,0,0), you can move that sprite anywhere on the screen and it will still show (as opposed to normal where you can display anything past the black borders).

You can use the commands GetScreenBoundsTop() (and Bottom/Left/Right) to find the virtual resolution location of the screen bounds. So if you want to place something at the top of the screen, instead of placing it at (0,0), you would place it at (GetScreenBoundsLeft() ,GetScreenBoundsTop()). In fact, when using this method, you should never position an object absolutely, always place it relative to the ScreenBounds.

It's a pain to constantly type out those commands, so I recommend you put the following (or similar) lines at the top of you init file:

Because of the way constants work in AppGameKit, you can call "sbT " instead of typing out "GetScreenBoundsTop()" every single time. sbcX=ScreenBoundsCenterX, sbH=ScreenBoundsHeight etc.
So if you want to place a sprite in the middle of the screen, you would do it as such: SetSpritePosition(ID,sbcX,sbcY) (subtracting half the sprite width of course).


Alternatively you can simply set the game aspect ration to 16:9, and just fade the edges of your background image out to black so it doesn't look strange having black borders. It's much easier this way

My Games - Latest WIP - My Website: Immortal.Digital - FB - Twitter
130,000 installs with AppGameKit and counting
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 2nd Jun 2017 08:25
Thanks guys, will check it! I'm just curios about this 100x100 virtual resolution but will play a bit with it!
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 2nd Jun 2017 15:05 Edited at: 2nd Jun 2017 15:26
Hi there,

ok I've played a bit. Working landscape as my example above works fine but for portrait the same(!) code fails, is there a bug?

Landscape working example:



Portrait NOT working example:



I'm totally lost now. I mean the second example is exactly the same like for landscape but the floating layout simply doesn't work the same way!

When you look at the attached image you see that square. For portrait mode this is stretched even though this should not happen!

edit: I see that's the case for landscape too... Well back to drawing board.

Another question: When using a virtual resolution of 100x100 doesn't this mean that everything is pretty blurred when it comes to sprites?

Attachments

Login to view attachments
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 2nd Jun 2017 15:36
Ok, so back to the drawing board as I said. Here's a simplified example:



I create a windows with 640x360 and create a virtual resolution with 640x360 and load a background image with 640x360... Why on earth is the result not the same as the background itself?

Attachments

Login to view attachments
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Jun 2017 19:24
try the sprite load after initialising the screen, any maybe set the the sprite size.
GetVirtualWidth () GetVirtualHeight () + size of screenbounds.
AGK (Steam) V2017.05.15 : Windows 10 Pro 64 Bit : AMD (17.4.4) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Xaron
10
Years of Service
User Offline
Joined: 3rd May 2014
Location: Germany
Posted: 2nd Jun 2017 19:41
Markus, you're a genius! Creating the sprite after initialising the screen solved that issue.

Login to post a reply

Server time is: 2024-11-24 15:01:32
Your offset time is: 2024-11-24 15:01:32