I'm working on a casual game with a few people which requires animations of sprites. The problem I am having is with cutting up the images. Some images are cut, while others are not, and it's seemingly random.
The demo can be found here which shows the problem:
http://www.stirkenheimer.com/panicst...demo/Test.html .
Each image is loaded with a
ImageLoader class, which opens the picture, adds it to a
MediaTracker, and then displays the image to the applet. When any animated object is created, I use an
ImageStrip class to cut it up. This will also display the image if it worked.
Sometimes, it will cut the images and sometiems not. I've found from the console debugging that it does find the size of the image, but for some reason creates a blank image after cropping out the cells. Here's the code i use to cut the images:
public void createCells(Applet app, Image img, int cellWidth, int cellHeight,
int extentTopX, int extentTopY, int extentBottomX, int extentBottomY)
{
int FramesAcross = ((img.getWidth(null) - extentTopX - (img.getWidth(null) - extentBottomX)) / cellWidth);
int FramesHigh = ((img.getHeight(null) - extentTopY - (img.getHeight(null) - extentBottomY)) / cellHeight);
System.out.println(FramesAcross + " " + FramesHigh);
if(frames != null)
{
frames.clear();
numFrames = 0;
}
frames = new LinkedList();
try
{
for(int i = 0; i < FramesAcross; i++)
{
for(int j = 0; j < FramesHigh; j++)
{
Image cell = app.createImage(new FilteredImageSource(img.getSource(),
new CropImageFilter((i * cellWidth) + extentTopX, (j * cellHeight) + extentTopY,
cellWidth , cellHeight)));
// Wait for image
MediaTracker mt = new MediaTracker(app);
mt.addImage(cell, 0);
try {
do {
mt.waitForAll();
} while (!mt.checkAll());
} catch (InterruptedException e) { System.out.println("Image is not loaded."); }
app.getGraphics().drawImage(cell, 0, 0, app);
// Return
addFrame(cell);
}
}
}
catch (Exception e){}
}
What I'm looking for is any suggestions as to what the problem may be, or if there is a better way to cut up the images to store as seperate pictures to quickly animate with. Thanks.