This draws blocks on the screen from a grid to make a background for my game. I am wondering if anyone has any suggestions on optimizing it for speed.
int blockwidth=blocksize-2;
//Draw coloured blocks
for (int x=0;x<sizex;x++){
int screenx=-(int)camerax+(x*blocksize);
if (screenx>-blocksize && screenx<gamewidth){
for (int y=0;y<sizey;y++){
int screeny=-(int)cameray+(y*blocksize);
if (screeny>-blocksize && screeny<gameheight){
if (tiles[x][y][0]>0){
g.setColor(new Color( tiles[x][y][1]));
//g.fillRect(screenx,screeny,blockwidth,blockwidth);
g.drawImage(Iloader.Imagelist.get(0), screenx,screeny, screenx+blockwidth,screeny+blockwidth, graphicsize,0,graphicsize*2,graphicsize, null);
} else {
//g.setColor(new Color( tiles[x][y][1] | 0xFFFF0000));
g.setColor(new Color( tiles[x][y][1]));
g.fillRect(screenx,screeny,blockwidth,blockwidth);
}
}
}
}
}
paintComponent
or similar? Have you checked how often that method is called? How often does the tiles actually change? \$\endgroup\$tiles[x][y][1]
ortiles[x][y][0]
change? \$\endgroup\$