3
\$\begingroup\$

What is the best general approach to implement scrolling for a 2D tile based game?

I need to scroll the map with a constant speed, lets say 2 pixels every frame (like in a top down shooter).

The tiles are 32x32 and the map is quite big, lets say 10 x 300.

There are 2 layers: - first is the background layer - second is the forgeground layer with obstacles and enemies

The target plattform is android and I want to use OpenGl.

What is best practice?

a) Draw only the visible Screen all the time (every frame) b) Load complete map into memory and just move the camera

Is there a difference in performance and determining collision etc.?

Thanks for any help!

\$\endgroup\$
3
\$\begingroup\$

I can't answer specifically for Andriod as I have never done anything for it, but generally you will want to only draw the portion of the map that is visible. It requires much less memory to do it, and shouldn't mess with collision at all. In fact, you will only need to check for collision on the objects you are drawing rather than the entire map.

If you want to have the bottom layer move at a separate speed than the top, the technique is called Parallax Scrolling.

\$\endgroup\$
  • \$\begingroup\$ Yeah, actually my question is platform independent. Thanks for your answer. Allways draw only what you need to see. To get a smooth scrolling I guess you should generate also some offset (e.g. one additional row of tiles) - right? \$\endgroup\$ – Alois Schweitzer Jul 28 '11 at 7:04
  • \$\begingroup\$ Yes, I always draw an additional row/col on each side of the screen. \$\endgroup\$ – user159 Jul 28 '11 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.