Question

I have a simple game I made in java. Essentially, my programming ability is relatively basic, and I would like to be able to resize the window the game is in and not have the images stay where they are and just display whiteness in the larger area. Here's a Screenshot. Is there any simple way to do this?

Was it helpful?

Solution

The two existing answers seem to presume you wish for the game space to resize.

Resize the game space

A game space that is a shoot'em'up does not necessarily resize well. E.G. When the game is twice as wide, should the left/right arrow presses move the ship twice as fast? Does stretching the window vertically increase gravity, or the speed of shots?

Pad the game space

The way I read the question, you simply wish to center the game space in the window. E.G.s of that can be seen in this answer.

Fix the size of the top-level container.

Many games fix the size to avoid the types of problems created by the 1st approach, and avoid the 'big blank bands' around the 2nd approach. This is as simple as calling setResizable(false).

For this technique to work best:

  1. Ensure the component doing the game rendering has a preferred size set.
  2. Add it (and all other controls) to the frame.
  3. Call frame.pack() to ensure the frame is the right size to display the content.
  4. (Finally) call frame.setResizable(false).

OTHER TIPS

To stretch the game, first render it on to an Image. Then draw the image while stretching it instantly.

Image dbImage; // The backbuffer
graphics.drawImage(dbImage, 0, 0, getWidth(), getHeight());

And most games prefer to disable the window resizing along with my engine.

Based on what I understand of your question, you want to "stretch" your game beyond the boundaries and extend it to the rest of the window. (If that's wrong, oops :s)

In order to accomplish this, you have to make some decisions. You can either scale the entire game to the frame, or just extend the background. But depending on what direction you want to move in, you'll have to do different things.

In the end this decision is entirely up to you.

Also what are you using to create the window?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top