|
import java.awt.image.*;
import java.awt.*;
import java.applet.*;
public class Sprite {
private String name;
public int[] b;
public int w;
public int h;
public Sprite(Applet a, String filename, int width, int height) {
try {
name=filename.substring(0, filename.indexOf('.'));
w=width;
h=height;
Image img=a.getImage(a.getDocumentBase(), filename);
b=new int[h*w];
PixelGrabber pg= new PixelGrabber(img, 0, 0, w, h, b, 0, w);
pg.grabPixels();
if (pg.status()==192) {
throw new RuntimeException("error loading "+filename +" sprite");
}
//now b[0] is the leftest pixel of the top
// b[w-1] is the rightest pixel of the top
} catch(Exception e) {
e.printStackTrace();
}
}
}
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|