简体   繁体   中英

How to make my 800*600 game fit all screen resolutions?

I have created a game that is 800*600. How can i make it so that it will fit all computer screens? How would this normally be done? Other sites have said too set everything to a certain ratio depending what the screen resolution is. But if each image in the game changes size in comparison to the screen resolution it would mean that the images would not be in the right places and cause other problems. Is it possible to just "Stretch out" my 800*600 game so it fits any size? Thanks

You need to make the game resolution-independent. That means you create your own concept of 'game units' (which might be exactly the same as pixels relative to an 800x600 screen if you want), and then operate exclusively on those game units.

Whenever you draw something to screen you convert co-ordinates and sizes from game units into pixels. You will need to have functions that can convert both ways, because you may also want to translate click-events from screen space to game space.

When you start your game, you need to decide on the screen resolution and aspect ratio. If the aspect ratio is not the same ( eg widescreen), you might choose to either stretch the game area or letterbox it. By moving all the translation code to a lower level and operating only within your game units, you save yourself a lot of pain in the long run.

Yes, you can stretch it out. Make the Games' main components on a JPanel that is 800 by 600, and add that JPanel to your JFrame. Then the player can resize your JFrame and the components won't go offscreen, they will change shape and size based on the new size of the JFrame. Remember that the mouse's position in relation to the JFrame will change a bit, but divide the mouses position by the JFrames height/width and multiply it by the JPanel height/width to get the position in relation to the JPanel. With this method you can let the user maximize your game and still have components look normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM