making a scrolling background. There is one problems with this code below.
I am drawing a image and it stay there on left of screen. i want to del it and create new one so there aren't 100's of background images on left. i just want to keep 2 background images. This way it will save some memory.

//top of class
int x = 0;
int x2 = Main.WINDOW_WIDTH;
...
//game loop
x-=2;
x2-=2;
...
//paint method
g.drawImage(Levels.getBGImage1(), x, y, width, height, null); 
g.drawImage(Levels.getBGImage1(), x2, y, width, height, null);

if(x+Main.WINDOW_WIDTH < 0){
    x = Main.WINDOW_WIDTH;
    g.drawImage(Levels.getBGImage1(), x, y, width, height, null);
}
if(x2+Main.WINDOW_WIDTH < 0)
{
    x2 = Main.WINDOW_WIDTH;
    g.drawImage(Levels.getBGImage1(), x2, y, width, height, null);
}

Recommended Answers

All 2 Replies

just reset the position to where you started and reuse the instance :)

cant belive i got caught in finding remove method online that i missed a simple solution.

Thanks alot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.