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?