Do you really want to do split the image up? We use multiple animation frames in our games but leave them all on a single image. I presume you want do draw a specific frame of animation, if so this is what you need:
1
| drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) |
This will draw a subsection of the image. To get a specific frame from the image either store the offsets into your array and read from them when you come to draw:
1 2 3 4
| void drawFrame(Graphics g,Image i, int x, int y, int frame) { g.drawImage(i, x, y, x+WIDTH, y+HEIGHT, frameOffsetX[frame], frameOffsetY[frame], frameOffsetX[frame]+WIDTH, frameOffsetY[frame]+HEIGHT, null); } |
WIDTH & HEIGHT are the sizes of the frames themselves.
If the frames are all the same size and arranged:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
etc.
just convert the index into the offsets like so:
1 2
| int sx1 = (frame&3)*WIDTH; int sy1 = (frame>>2)*HEIGHT; |
This saves using the arrays for the offsets into the image.
Its good to get into the habit of doing this, as when it comes to accelerating images with hardware you get better perfromance by using a few large images than many small ones.
I hope this helps, otherwise it should give you something to think about

Good luck with your game programming,
- Dom