Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- import tilegame.debug.Debug;
- /**
- * This class is responsible for loading in images
- * @author Kenneth
- *
- */
- public class ImageLoader {
- /**
- * This method tries to load in the selected image from the path given.
- * @param path
- * @return
- */
- public static BufferedImage loadImage(String path){
- try {
- return ImageIO.read(ImageLoader.class.getResource(path)); //Loads in image
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(1); //If the image cannot be loaded, the window closes
- Debug.LogError(path + " was not loaded.");
- }
- return null;
- }
- }
- import java.awt.image.BufferedImage;
- /**
- * This class is responsible for splitting up sprite sheets into multiple images.
- * @author Kenneth
- *
- */
- public class SpriteSheet {
- private BufferedImage sheet;
- /**
- * This constructor receives the image that needs to be modified.
- * @param sheet
- */
- public SpriteSheet(BufferedImage sheet){
- this.sheet = sheet;
- }
- /**
- * This crops a sprite sheet to get the subimage within the picture.
- * @param x
- * @param y
- * @param width
- * @param height
- * @return
- */
- public BufferedImage crop(int x, int y, int width, int height){
- return sheet.getSubimage(x*width, y*height, width, height);
- }
- }
- public void drawImage(Texture texture, int x, int y, int width, int height) {
- texture.bind();
- glTranslatef((float) x, (float) y, 0);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(0, 0);
- glTexCoord2f(1, 0);
- glVertex2f(width, 0);
- glTexCoord2f(1, 1);
- glVertex2f(width, height);
- glTexCoord2f(0, 1);
- glVertex2f(0, height);
- glEnd();
- glLoadIdentity();
- }
Add Comment
Please, Sign In to add comment