Change Resolution (FullScreen) and Automatically Resize Game Elements

I have recently realized that I would like for my game to have the ability to go full screen, or standard resolution. I know that I can use this:


frame.setExtendedState(Frame.MAXIMIZED_BOTH);  

but when I do this, the game elements are still the same size, drawn to the top left, and the frame as a whole is fullscreen. I was thinking, maybe I should make a variable called screenSize and multiply all the width and height by that depending on the resolution, but as I have lots of code I really do not want to go back through and do that. This is all in Java2d. Thanks for any help -cMp

Yeah, you would have to do that, otherwise it’ll be very slow. The other option would be to stretch the double buffered image before drawing it to the canvas, but that can slow the frame rate dramatically depending on the resize filter and anti-alias chosen.

If you gave me more information on how you are setting up the frame, I might be able to give you a more cleaner example of how to do this.

Yeah here’s my main setup of repainting and updating:


	public void run() {
		long lastLoopTime = System.nanoTime();
		final int TARGET_FPS = 100;
		final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;

		while (inRealGame) {
			updateParticles();
			if (inGame) {
				long now = System.nanoTime();
				long updateLength = now - lastLoopTime;
				lastLoopTime = now;
				delta = updateLength / ((double) OPTIMAL_TIME);

				lastFpsTime += updateLength;
				fps++;

				gamePhysic(delta);

				if (lastFpsTime >= 1000000000) {
					realFPS = fps;
					// frame.setTitle("(FPS: " + fps + ")");
					// System.out.println("(FPS: " + fps + ")");
					lastFpsTime = 0;
					fps = 0;
				}

				try {
					Thread.sleep((lastLoopTime - System.nanoTime() + OPTIMAL_TIME) / 1000000);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			repaint();
		}
	}

	public void updateParticles() {
		for (int i = 0; i <= particles.size() - 1; i++) {
			Particle part = particles.get(i);
			if (part != null) {
				if (part.update()) {
					particles.remove(i);
				}
				if (part != null) {

					if (part.getLoc().x <= 0) {
						part.getLoc().x = 0;
						part.getVel().x *= -.9;
					}
					if (part.getLoc().x >= 700) {
						part.getLoc().x = 700;
						part.getVel().x *= -.9;
					}
					if (part.getLoc().y <= 0) {
						part.getLoc().y = 0;
						part.getVel().y *= -.9;
					}
					if (part.getLoc().y >= 550) {
						part.getLoc().y = 550;
						part.getVel().y *= -.9;
					}
				}
			}
		}
		for (int i = 0; i <= overParticles.size() - 1; i++) {
			Particle part = overParticles.get(i);
			if (part != null) {
				if (part.update()) {
					overParticles.remove(i);
				}
				if (part != null) {

					if (part.getLoc().x <= 0) {
						part.getLoc().x = 0;
						part.getVel().x *= -.9;
					}
					if (part.getLoc().x >= 700) {
						part.getLoc().x = 700;
						part.getVel().x *= -.9;
					}
					if (part.getLoc().y <= 0) {
						part.getLoc().y = 0;
						part.getVel().y *= -.9;
					}
					if (part.getLoc().y >= 550) {
						part.getLoc().y = 550;
						part.getVel().y *= -.9;
					}
				}
			}
		}
	}

	public void gamePhysic(double delta) {
		if (!isFirst) {
			room.physic();
			mobSpawner();
			for (int i = 0; i < currLevel.mobs.length; i++) {
				if (currLevel.mobs[i].inGame) {
					currLevel.mobs[i].physic();
				}
			}
			if (currLevel.levelOver) {
				getNextLevel(currLevel);
			}
		}
	}

and for drawing things, I use the generic g.drawImage/fillOval(for some particles) and such. So you think I should have a variable that by default is one and when I maximize it set it to 3, 4, 5, 6 or whatever works and say g.drawImage(img, x, y, width * Screen.screenSizeMultiplier, height * Screen.screenSizeMultiplier, null);?

bump? I dunno if bump is for these forums… but bump anyways :wink: