A good way to do scrolling in games?

So here's my problem ... I've got a huge image (much bigger than 1280x1024) I want to use as a background. What would be a nice way of scrolling around this big image like other RTS games out there without having to make the whole huge image redraw itself at a different coordinate. It's pretty annoying to wrap my head around the idea that the screen really isn't moving but the image under is moving. thanks in advance

[431 byte] By [Edstera] at [2007-10-3 0:39:43]
# 1

First of all, it is simplest to repaint whatever part of the image is on the screen each frame, as otherwise you get into copying the already drawn image and moving it. However, if you are painting anything on top of the background, then that won't work, as you would be copying that stuff too. If you aren't painting anything on top, then use Graphics.copyArea to move the background, then setup a clipping rectangle over the areas that need to be repainted (if you moved it 1px left and 1px up, then the bottom 1px tall row and the right 1px wide column).

However, if you are painting stuff on top of the background, then just set a clipping rectangle over the area you want to paint the image over, then just draw the image in the proper position. Java will only (AFAIK) spend time painting the part of the image that is inside the clipping area, no matter how big the image is.

You may still want to break up that image into smaller ones to lessen the load on the user's ram and video memory - you are more likely able to fit a couple of the smaller images into the video memory than all of the big one, giving a performance increase.

Talchasa at 2007-7-14 17:33:49 > top of Java-index,Other Topics,Java Game Development...