Hey all!
I have a little problem with rendering tiles for my map, it really slowes down the whole game very much, I noticed that using “rotate” really wasnt as cheap as i belived.
As it is now, i can run the game without rendering the tiles and get a nice fps at 50, but if i render the tiles it slowes down to about 20, with the rotation involved the game spins in on about 5-10 fps, well this just is’nt feasible so i really would need some rendering tips from some of you gurus on the forum =)
Here is the rendering function anyway, maybe you guys can spot something there and give me some pointers on how to make the whole thing faster…
public void drawMap(Graphics2D g, Map m, int indexX, int indexY, short[] tileWidth, short[] tileHeight)
{
int tempIndexX = indexX;
boolean trans = false;
AffineTransform original = g.getTransform();
for(int i = tileHeight[0]; i < tileHeight[1]; i++)
{
for(int j = tileWidth[0]; j < tileWidth[1]; j++)
{
if(i >= 0 && j >= 0 && i < m.sizeY && j < m.sizeX)
{
if(m.MapTile[j][i].id == 0)
{
}
else
{
switch(m.MapTile[j][i].transform)
{
case 0:
break;
case 1:
g.rotate(1.5707963267949d, indexX+24, indexY+24);
trans = true;
break;
case 2:
g.rotate(3.1415926535898d, indexX+24, indexY+24);
trans = true;
break;
case 3:
g.rotate(4.71238898038469d, indexX+24, indexY+24);
trans = true;
break;
}
switch(m.MapTile[j][i].id )
{
case 1:
image = concrete1;
break;
case 2:
image = concrete2;
break;
case 3:
image = concrete2_c;
break;
case 4:
image = concrete2_cc;
break;
case 101:
image = wall1;
break;
case 102:
image = wall1_c;
break;
case 103:
image = wall1_cc;
case 201:
if(frame == 0)
image = dorr1f1;
else if(frame == 1)
image = dorr1f2;
else
image = dorr1f3;
break;
default:
image = concrete1;
break;
}
g.drawImage(image, indexX, indexY, 48, 48, null);
if(trans)
g.setTransform(original);
}
}
indexX += 48;
}
indexY += 48;
indexX = tempIndexX;
}
}
tnx
If you don’t absolutely require the rotation of large (or a bunch of) images in real-time then java2d should be sufficient, but otherwise you might want to look into using an opengl binding (lwjgl/jogl).