Tile map speed problem

Ok, I have a tile map type game with about 24x13 tiles per screen. To draw each frame, I would first go through each tile on screen and draw the background tiles. Then I’d go through again and draw the players/monster. This was working fine. However, I just added in item drops on the ground, which are drawn immediately after each background tile, when applicable. It only draws 1 item per tile max, 0 if no items are on the tile. However, when I put a lot of items on the tiles on screen, the frame rate slows down a whole lot. When I tested with lots of monsters on screen I didn’t have this problem.

Here’s the code where the items are drawn:

	public void drawMap(Graphics g, int x, int y,int offX,int offY) throws java.io.IOException{

		int startLocX = x - C.TILE_WIDTH_PER_SCREEN/2 - 2;
		int startLocY = y - C.TILE_HEIGHT_PER_SCREEN/2 - 2;

		for(int mapY= startLocY; mapY<y+C.TILE_HEIGHT_PER_SCREEN/2 +2; mapY++){

			for(int mapX= startLocX; mapX<x+C.TILE_WIDTH_PER_SCREEN/2+2 ;mapX++){

				int effectiveX=C.centerX + (mapX-x)*C.tileW+offX-30;
				int effectiveY = C.centerY + (mapY-y)*C.tileH+offY-26;

				g.drawImage(getTile(mapX,mapY),effectiveX,effectiveY,null);
				
				ArrayList<Item> items=getItems(C.TEST_MAP,mapX,mapY);
				if(items != null && items.size()>0)
					g.drawImage(items.get(items.size()-1).getPicture(),effectiveX,effectiveY,null);
			}
		}
                      }

The getPicture() method just returns a pointer to a pre-loaded buffered image, right now it’s just returning a default picture, regardless of the item.
Any ideas?

You missed to handle an nullpointer :

No, what I have written doesn’t miss any null pointers. I put the check for null first in an ‘and’ statement, the way java compiles, it checks the first test in the and, if it fails, then it doesn’t check the rest of the and statement, because FALSE and anything is false, so it’s optimizes it automatically by not checking the rest. So if != null is ever false (hence it is null), then it will never check the size any way, so there’s no exception thrown.

Besides, the problem I’m having isn’t that the program doesn’t run, or that it crashes, the problem is that it slows down.

Are those item images translucent perhaps?

and how were they created? new BufferedImage(), createCompatibleImage, Tookit?

This is how they’re created originally:

itemPallet = javax.imageio.ImageIO.read(new File(C.PICTURE_PREFIX+"items.gif"));
defaultPic = itemPallet.getSubimage(0,0,50,50);

Where itemPallet is a big gif image with all the items side by side, and each item pic is a subimage of that pallet, the defautPic is the only 1 being used right now, so getPicture()'s code is:

getPicture(){
    return defaultPic;
}

And the itemPallet.gif has a transparent background. It’s total size is about 3kB (not sure what parts of this matters :\ )

Also, I’m using the same methods for monster pictures, but I haven’t drawn those yet, so just using gif images I have laying around. The monster pics are about 2.4kB, so size isn’t much different. Although the monsters aren’t using pallets and subimages, and I plan to do something similar as this itemPallet in the future, so definitely need to work out what’s going wrong here.

First of all… the compressed size doesn’t matter. Eg you can create some 0.1kb png which is 30k x 30k pixels in size.

getSubimage is one of the slower methods… especially if the spritesheet exceeds 2^16 pixels. Try to copy em over as shown here:
http://www.java-gaming.org/forums/index.php?topic=16801.msg131902#msg131902

Wow, that helped TREMENDOUSLY oNyx! Thanks a ton!

Would you recommend I make create all my images in this fashion? I mean the ones that aren’t spliced, should I Still create them like this?