Handling varying screen resolutions

Started by
2 comments, last by Daaark 11 years, 6 months ago
Hello Gamedev!

Me and my girlfriend have been working on this fairly small game as a project for school for the last few months. This is the first major project we've taken on since we both started learning Java at the start of the year and as such we are constantly running into all kinds of issues that you encounter while mostly self-taught. So far we haven't gotten stuck in one place for too long (largely thanks to this great community), but now we've come to the quite significant issue of how to handle the oh-so-many varying screen resolutions which are found on computers these days. I've been looking 'round the web a fair bit and have so far found no real consensus on how this is supposed to be dealt with in a practical way.

With no other hope I finally got to making an account here on Gamedev and hope that someone would have an answer for us. For the project we decided that we wouldn't be using anything other than pure Java code, not using any pre-existing engines nor GUI builders such as the one in Netbeans. If any more info is needed for you to give a satisfying answer please let me know so.

Thanks in advance!
Advertisement
There are many ways to handle this.

You can draw your game into another image or texture, and then render that to the center of the screen. If the screen is bigger, draw a background image first, then the game screen over it. Lots of games do this to handle different aspect ratios. You could also scale the image to the size of the screen, but that will likely cause ugly blurring, or other artifacts.

You could draw your objects without assuming any game resolution. Just anchor them tot he edges of the screen (if it's a gui),

OR

Use normalized screen coordinates (0.0-1.0). This way, ScreenWidth * 0.5 is always the center of your screen. ScreenWidth * 0.0 is always the left edge. ScreenWidth * 1.0 is always the right edge.

Or

You could just draw more.

Depends. Show us what your game looks like, and explain a bit more.
Well, the thought is that it's a fairly simplistic top-down game. The screen will be divided into two fields, a top one for the actual "game screen" (in lack of a better word, while the bottom part contains all of the interface stuff such as a dialog box and inventory. For this we figured that we'd just make two JPanels, one for the top and one for the bottom and divide the smaller one into three sub-panels. This is all just in the planning stage right now as we didn't want to have to go back and re-do everything once we found a way to do it so I don't have any actual images to show.

The game screen itself is planned to simply consist of a background image of the current room the player is located in (with floor, walls and some non-movable furniture) while anything else (the player, npcs, interactable objects) will be drawn onto this image later. I figure this is probably the standard approach to these kinds of things. I'm quite interested in the first suggestion you made (I assume that's also how you get the "black edges"), but isn't there a risk that the actual game screen will be very tiny on certain monitors in that case?
You can scale the image before you center it on the screen. Just compare against the actual screen size, and then scale it up to the best size that will fit without changing the image's ratio!

This topic is closed to new replies.

Advertisement