painting image background separately with the player image
i want to paint the image background on a JFrame once only. So i have a the following codes..
publicvoid paint(Graphics g)
{
g.drawImage(sea,0,0,this);
for(int across = 0; across < width ; across++)
{
for(int vert = 0; vert < height ; vert++)
{
if (map.A[vert][across] == 3)
{
g.drawImage(treasure,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 4)
{
g.drawImage(bottomLeft,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 5)
{
g.drawImage(midLeft,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 6)
{
g.drawImage(topLeft,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 7)
{
g.drawImage(topCenter,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 8)
{
g.drawImage(topRight,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 9)
{
g.drawImage(midRight,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 10)
{
g.drawImage(bottomRight,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 11)
{
g.drawImage(bottomCenter,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 12)
{
g.drawImage(center,across*TILE_SIZE,vert*TILE_SIZE,this);
}
elseif (map.A[vert][across] == 13)
{
g.drawImage(grass,across*TILE_SIZE,vert*TILE_SIZE,this);
}
}
}
}
This code works fine and showed the image.
However when i wanted to paint the player image, (using a while loop to keep checking and updating the player position and show on the JFrame)...
publicvoid gameLoop()
{
gameRunning =true;
// keep looking while the game is running
while (gameRunning)
{
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
render(g);
// flip the buffer so we can see the rendering
g.dispose();
strategy.show();
logic();// the player movement
//pause a bit so that we don't choke the system
try{ Thread.sleep(4);}catch (Exception e){};
}
}
The background image will not show but only the player. The background appears white in colour.
Can anyone help how to paint the 2 things separately?

