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 / FREE CODE - Perfect solution to run on all resolutions.

Author
Message
The Slayer
Forum Vice President
14
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 7th Jan 2012 17:11
Hey everyone,

I made this little piece of code that will make your games run on ALL resolutions (even odd ones that don't exist, like 501x307 for instance ), without having black borders around your playfield area or squished/distorted images.
So, no more black borders, no more 'oval' circles or rectangular squares. Hehehh.
By changing the resolution values in the setup.agc file, you can make your game run at ANY desired resolution, and have perfectly shaped sprites and no black borders.
The only 'issue' is that one needs to change the values in the setup file to change resolutions, but it should be fairly easy to code a resolution selection feature in your game and write the new values to the setup.agc file, and ask the user to restart his game in order for the changes to take effect.

Feel free to use the code in your programs.

Here are all the necessary files, including full source code and media used.

Cheers

Attachments

Login to view attachments
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 8th Jan 2012 00:10
It works quite well except when it comes to images that take up (or are supposed to) the entire screen. Since the -1 parameter is used in the SetSpriteSize() command it keeps the image's shape correct but won't fit perfectly into the screen. Accomplishing this is impossible without changing the image's width : height ratio.

A simple analogy. Imagine (or use a graphics editor) a square and a rectangle. Now try to get that square to fit inside that rectangle. You'll end up:
a) chopping part of the square off
b) changin its width : height ratio resulting in a rectangle
c) with borders.

I'm currently working on a solution which allows the developer to use their own borders instead of putting up with black ones. If you're clever enough, you can disguise the borders as part of the background.

There is one flaw with this system though. If the 'Game Screen' (see code) has a ratio that is smaller than the real screen's ratio (divide width by height and use the decimal value to compare) then it won't work. 1024x600 is a good resolution for the 'Base' Game Screen (see code) as few ratios exceed this.

A small demo is attached so feel free to test it against any resolution which has a ratio smaller than 1.706. I'll try to make something a bit more impressive later.

Attachments

Login to view attachments
The Slayer
Forum Vice President
14
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 8th Jan 2012 01:05
Thanks, Hodgey.

Yeah, for images that need to fill the entire screen, it is not perfect. Creating a solution where there's no borders or squished/stretched images that works on ALL resolutions is nearly impossible.
This method works well for sprites/images that don't fill the entire screen.
For images that need to fill the entire screen, you could always make 'em big enough to fill the gaps.

Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 9th Jan 2012 14:09 Edited at: 9th Jan 2012 14:10
I used an solution on boinkadroid where iam detecting the resolution on the device and then setting virtual resolution with it.

And then have preset values for various tasks.

But i dont know how it works on all devices as i only have one

But that source is now open source in the showcase if anyone wants to see how it works?

Login to post a reply

Server time is: 2024-04-25 07:52:02
Your offset time is: 2024-04-25 07:52:02