I am new to java and am trying to turn some of my C++ game projects into java applets. My double buffering is not working, I am getting a lot of flicker when I try to scroll the background. Can someone please tell me what I am doing wrong? I don’t see how I am getting flicker since the map is being drawn to the buffer image, then to the screen.
public void init( ) {
tile[SKY] = getImage(getDocumentBase(), "sky.png");
tile[CLOUD_1] = getImage(getDocumentBase(), "cloud_1.png");
tile[CLOUD_2] = getImage(getDocumentBase(), "cloud_2.png");
tile[RED_BRICKS] = getImage(getDocumentBase(), "red_bricks.png");
buffer = createImage(APPLET_WIDTH, APPLET_HEIGHT);
bufferg = buffer.getGraphics();
addKeyListener(this);
}
public void paint(Graphics g) {
if(buffer != null) {
int tile_id;
for(int y=0;y<MAP_ROWS;y++) {
for(int x=0;x<MAP_COLS;x++) {
tile_id = map[y][x];
bufferg.drawImage(tile[tile_id], x * TILE_SIZE, y * TILE_SIZE, this);
}
}
}
g.drawImage(buffer, screenX, screenY, this);
}