Advertisement
Guest User

SpriteSheet

a guest
Jun 13th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package com.thecherno.rain.graphics;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.io.IOException;
  5.  
  6. import javax.imageio.ImageIO;
  7.  
  8. public class Spritesheet {
  9.    
  10.     private String path;
  11.     public final int SIZE;
  12.     public int[] pixels;
  13.    
  14.     public static Spritesheet tiles = new Spritesheet("/textures/spritesheet.png", 256);
  15.     public Spritesheet(String path, int size) {
  16.             this.path = path;
  17.             SIZE = size;
  18.             pixels = new int[SIZE*SIZE];
  19.             load();
  20.     }
  21.    
  22.     private void load() {
  23.             try {
  24.                     BufferedImage image = ImageIO.read(Spritesheet.class.getResource(path));
  25.                     int w = image.getWidth();
  26.                     int h = image.getHeight();
  27.                     image.getRGB(0, 0, w, h, pixels, 0, w);
  28.             } catch (IOException e) {
  29.                     e.printStackTrace();
  30.             }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement