Creating A Scrolling Background

Hey what’s up? this is my first time creating a game on java and I’m going to need help with creating a scrolling background. My project is going to like a classic arcade scrolling shooter game. If any help can be given it would be greatly appreciated. Please suggest some sites to go to.

I’ve tried java on the brain with his game Warp but his background is too complex for me to understand since he also has objects that you can blow up and objects that you can hit appear on the background. I just want a scrolling background cause the user will pilot a plane and ya. So any hlp will be greatly appreciated. Thanks

You might check out my GAGE2D library for a working API for scrolling maps (including Parallax scrolling!).

The theory is actually quite simple. The only code you need is the code necessary to fill a screen with tiled images. e.g.:

BufferedImage myimage = loadImage();
Graphics g = //get graphics

int width = myimage.getWidth();
int height = myimage.getHeight();
int mapWidth = //Get map width
int mapHeight = //Get map height

int tilesx = screenWidth/width;
int tilesy = screenHeight/height;

for(int y=0; y<tilesy; y++
{
    for(int x=0; x<tilesx; x++)
    {
        g.drawImage(myimage, x*width, y*height, null);
    }
}

Do you follow that code? If so, then scrolling is simply a matter of adding an offsetx and offsety, where the offset is how much the map is scrolled. i.e. Change the drawImage line to:

g.drawImage(myimage, x*width-offsetx, y*height-offsety, null);

Optimizations to that loop are left for you to contemplate. :slight_smile:

Thank you very much, you would not believe how much this going to help me for a first timer :stuck_out_tongue: I’ll post again if I need more help, thanks again

[quote]Thank you very much, you would not believe how much this going to help me for a first timer :stuck_out_tongue: I’ll post again if I need more help, thanks again
[/quote]
You’re welcome. :slight_smile: And just be glad these forums exist these days. When I first got started in gaming (a decade or two ago), I wrote to the shareware association of america asking if they had any resources to help a starting shareware programmer write scrolling code. I got a very nice and polite letter back stating that their members may be of more help in that area, without actually stating who those members might be.

Thank God for computer science and wonderful books like Tricks of the Game Programming Gurus! Without those, I might have never cracked such obviously simple things. (To an experienced software engineer, that is.) :wink: