Check this out, oNyx, I tried to use the code that you posted and that’s what i ended up with:
public Sprite getSprite(String ref) {
// if we've already got the sprite in the cache
// then just return the existing version
if (sprites.get(ref) != null) {
return (Sprite) sprites.get(ref);
}
BufferedImage sourceImage = null;
try {
sourceImage=ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream(ref)));
if(sourceImage == null)
{
fail("Can't find ref: "+ref);
}
}catch(IOException e){
e.printStackTrace();
}
// create an accelerated image of the right size to store our sprite in
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
Image image = gc.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),Transparency.BITMASK);
// draw our source image into the accelerated image
image.getGraphics().drawImage(sourceImage,0,0,null);
// create a sprite, add it the cache then return it
Sprite sprite = new Sprite(image);
sprites.put(ref,sprite);
return sprite;
}
The parameter ref that comes in to the function is for example “/sprites/ball.gif”
I tried to run the jar file with this and the code still breaks at the fail in this function and I still get this message: Can’t find ref: /sprites/ball.gif
Am I doing something wrong again? >< thx for all the help. 