I wanted to make an spritesheet class for my java game . In past when i wanted to crop an image out of my spritesheet i used to use BufferedImage croping method , but its not working for me becuase i cant load the images when im loading images when they are in the jar file.
Now Im using Image Class . I searched an i found a crop method in Image class but i cant make it work .
what am i doing wrong ?
My SpriteSheet class :
package Maya.Core;
import java.awt.*;
public class Spritesheet{
Texture sprite;
public Spritesheet(String path){
sprite = new Texture(path);
}
public Image GetImage(Rect wantedRect){
return sprite.image.crop(wantedRect.x,wantedRect.y,wantedRect.width,wantedRect.height);
}
}
My texture class:
public class Texture {
public Image image;
public Texture(String path) {
Toolkit defaultToolkit = Toolkit.getDefaultToolkit();
URL imageResource = Window.class.getClassLoader().getResource(path);
image = defaultToolkit.getImage(imageResource);
}
}