Possible Duplicate:
Converted Java Game to Applet; Wont load pictures
I have a single image for all my ground textures, like a spritesheet but just vertical, and it just gives me the first block (grass) every time. Heres the code for loading and cropping the image:
for (int i = 0; i < Screen.tileset_ground.length; i++) {
URL imgUrl = getClass().getResource("tileset_ground.png");
Screen.tileset_ground[i] = getImage(imgUrl);
ImageFilter imgF = new CropImageFilter(0, 26 * i, 26, 26);
ImageProducer imgP = new FilteredImageSource(Screen.tileset_ground[i].getSource(), imgF);
Screen.tileset_ground[i] = createImage(imgP);
}
First, you need to move the first two lines in the for loop outside of it. You only need to do that step once.
Secondly you need to figure out how many tiles are in your tileset and only iterate that many times.
So maybe something like this?