Advertisement
Guest User

Java2D_SpriteSheet

a guest
Nov 11th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. package j2dgame.gfx;
  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. public String path;
  11. public int width;
  12. public int height;
  13.  
  14. public int[] pixels;
  15.  
  16. public SpriteSheet(String path) {
  17. BufferedImage image = null;
  18.  
  19. try {
  20. image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
  21. } catch (IOException e) {
  22. e.printStackTrace();
  23. }
  24.  
  25. if (image == null) {
  26. return;
  27. }
  28.  
  29. this.path = path;
  30. this.width = image.getWidth();
  31. this.height = image.getHeight();
  32.  
  33. pixels = image.getRGB(0, 0, width, height, null, 0, width);
  34.  
  35. for(int i=0;i< pixels.length;i++){
  36. pixels[i]=(pixels[i] & 0xff)/64;
  37. }
  38. }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement