How can I resize a set of sprite images?
Posted
by
Tyler J Fisher
on Game Development
See other posts from Game Development
or by Tyler J Fisher
Published on 2012-03-21T06:02:24Z
Indexed on
2012/03/21
17:39 UTC
Read the original article
Hit count: 555
Hey StackExchange GameDev community, I'm attempting to resize series of sprites upon instantiation of the class they're located in.
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 = wLeft.getScaledInstance(wLeft.getWidth()*2, wLeft.getHeight()*2, Image.SCALE_FAST);
}
© Game Development or respective owner