Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

SpriteSheet

By: a guest on May 29th, 2013  |  syntax: None  |  size: 0.60 KB  |  views: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class SpriteSheet {
  2.        
  3.         private String path;
  4.         final int SIZE;
  5.         public int[] pixels;
  6.  
  7.         public static SpriteSheet tiles = new SpriteSheet("/textures/SpriteSheet.png", 256);
  8.        
  9.         public SpriteSheet(String path, int size) {
  10.                 this.path = path;
  11.                 this.SIZE = size;
  12.                 pixels = new int[SIZE*SIZE];
  13.                 load();
  14.         }
  15.        
  16.         private void load() {
  17.                 try {
  18.                         BufferedImage image = ImageIO.read(SpriteSheet.class.getResource(path));
  19.                         int w = image.getWidth();
  20.                         int h = image.getHeight();
  21.                         image.getRGB(0, 0, w, h, pixels, 0, w);
  22.                 }
  23.                 catch (IOException e) {
  24.                         e.printStackTrace();
  25.                 }
  26.         }
  27.  
  28. }