I am currently making a 2D game using Java (Java 2D). I want to make my game resizable. If you play any game on an emulator (e.g. legend of Zelda in fceux emulator) in full screen mode, you'll see that the 8-bit or 16-bit game re-sizes to fit the screen size. How can I implement the same thing in my game programatically?
I'm assuming you're using the standard Java 2D API, not OpenGL.
In that case, you render your graphics to a buffer image first. Then, to render that image to the screen, you can either use a Graphics.drawImage call that allows resizing your buffered image:
public abstract boolean drawImage(Image img, // the buffer image
int dx1, int dy1, int dx2, int dy2, // 0, 0, screen.w, screen.h
int sx1, int sy1, int sx2, int sy2, // 0, 0, image.w, image.h
ImageObserver observer) // null is fine
or, if you want to have more control over the scaling algorithm, you can first convert the image to a second buffered image using the following method of the
public Image getScaledInstance(int width, int height, int hints)
Here, the parameter
hints is one of
See the API doc for details. For bigger games, you might want to keep an eye on performance doing these rescales, but for typical 8-bit resolutions you should probably be fine.