Hi all,
I am trying to write a 2d shooter in java. I want to have the background rotate rather than the ship rotate because I’m difficult like that. I tried using affine transforms but found them to be very slow.
Instead I decided to try loading in a large number of images (64 at 800*600 in 256 colour gifs) and display the appropriate image to show the background rotating.
This works fine when I only load 50 or so images but when I load more than that number the program suddenly exits without throwing any exceptions.
I loaded each of the images by popping the following code into a method and calling it in a loop assigning each of the images to an array element.
Toolkit tk = Toolkit.getDefaultToolkit();
Image im1=tk.createImage(imageName);
MediaTracker tracker = new MediaTracker(mainFrame);
tracker.addImage(im1,0);
try
{
tracker.waitForID(0);
}
catch ( Exception e )
{
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(“We’ve messed up somewhere in the image loading”);
System.exit(0);
}
If it makes any difference I am using full screen exclusive mode. The version of the jdk I am using is 1.4.2_03
What I find interesting is that it always fails on the second frame. i.e. it draws the first frame fine along with all the calls to drawImage then fails when I call drawImage on the ship image for the second time. I tried using a smaller ship graphic and this worked but I want to use the original one!
Given that using a smaller image for the ship allows it to work (The larger one contains multiple animation frames the smaller only one) I assume this must have something to do with memory on the graphics card. This seems a little odd to me as when I check the memory usage of the java process in windows it shows I am using 74Mb of memory in total and I have a 128Mb graphics card.
I would have expected that if the graphics card was full java should just hold the image in main memory instead and the performance would degrade. If it is an error throwing situation I would have expected an exception of some kind to be thrown or for the java process to quit with some kind of error.
Am I doing something daft or is it java?
Thanks for reading.