Java - Resize images upon class instantiation
- by Tyler J Fisher
Hey StackExchange GameDev community, I'm attempting to:
Resize series of sprites upon instantiation of the class they're located in (x2)
I've attempted to use the following code to resize the images, however my attempts have been unsuccessful. I have been unable to write an implementation that is even compilable, so no error codes yet.
wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST);
I've heard that Graphics2D is the best option.
Any suggestions?
I think I'm probably best off loading the images into a Java project, resizing the images then outputting them to a new directory so as not to have to resize each sprite upon class instantiation. What do you think?
Photoshopping each individual sprite is out of the question, unless I used a macro.
Code:
package game;
//Import
import java.awt.Image;
import javax.swing.ImageIcon;
public class Mario extends Human {
Image wLeft = new ImageIcon("sprites\\mario\\wLeft.PNG").getImage();
//Constructor
public Mario(){
super("Mario", 50);
wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST);
}
Thanks!
Note: not homework, just thought Mario would be a good, overused starting point in game dev.