public void paint(Graphics gOld)
{
if(backBuffer!=null)
{
Graphics g = backBuffer.getGraphics();
int x = 0;
int y = 30;
int count = 0;
for(int a = 0; a <= NO_OF_TILES; a++)
{
g.drawImage(tileSprites[tileCode[a]], x, y, null);
x+=50;
count ++;
if(count == 15)
{
count = 0;
x = 0;
y+= 43;
}
}
...
Draw player sprite and enemies.
...
g.dispose();
gOld.drawImage(backBuffer, 0, 0, null);
gOld.dispose();
}
}
I have an array of BufferedImages (tileSprites) and an array of which tile should be displayed in which position of the screen (tileCode). However this code is running really slow when my character walks around it. The screen is 15x15 tiles big.
Any ideas how I can improve performance here ?
Cheers
Chris
[Edited by - chris_j_pook on June 6, 2005 4:03:04 PM]
[java] Tiled java game
Hi,
Im making a game similar to Zelda using tiles...
In my paint loop I have this ...
Your problem is probably in the g.drawImage function. One way you can improve on this is to render the screen to a background image, then when the screen moves you draw part of that background image to the screen in a new position. The portion of the screen that is newly visible is the only part you will have to redraw individually.
This only works if your background image is static. If you have flowing water or any other moving image on your background this will not work.
Also, what speed is the computer you're using? In one of my games I do the same thing but in python, which is a bytecode interpretted language. The loop is similar, but runs at about 150 frames per second at 640x480 resolution. I can't imagine how this loop could run slow on your computer when compiled unless there is something drasticly slow in your g.drawImage function.
This only works if your background image is static. If you have flowing water or any other moving image on your background this will not work.
Also, what speed is the computer you're using? In one of my games I do the same thing but in python, which is a bytecode interpretted language. The loop is similar, but runs at about 150 frames per second at 640x480 resolution. I can't imagine how this loop could run slow on your computer when compiled unless there is something drasticly slow in your g.drawImage function.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement