I'm looking for a tutorial about how to implement a horizontally scrolling background with various objects that auto-scrolls as your character/player moves just like various car/motorbikes games.

I'll have images for various obstacles, objects along the path. I'm concerned if I load everything on start of game. /i would want these to be loaded for visible area as the player moves (or appears to move).

Though I'm looking for a tutorial in android and I'm new to opengl, but I welcome any sort of help.

  • \$\begingroup\$ I don't have time right now to give you a proper answer, but I would start by reading this article on parallax scrolling: illogictree.com/blog/2009/01/… I would also argue that implementing parallax scrolling comes secondary to just getting something up and running on the screen. So this article is for AFTER you've learned that ;) \$\endgroup\$
    – Nailer
    Aug 15, 2011 at 10:28

1 Answer 1


If your data is small enough, just load everything right into memory but be sure to cull objects that are not within the dimensions of the screen. This can be as simple as a rectangle on rectangle intersection test. Doing this will save precious time in the graphics pipeline. OpenGL must do quite a bit of work before it can safely discard invisible shapes, it's best to do this work before sending the vertices to OpenGL.

Another option is to load chunks of your level into memory, discard chunks that are no longer visible. Chunks should be at least the size of your screen to be effective (going any smaller would probably be overkill). Culling here is also important; even if you're chunk is on screen, that doesn't mean all of it will be. You would want some sort of method of detecting when a chunk is close to being in view (for example being close to the edge of a screen, but not on-screen yet). Load in a chunk when it is close enough and unload when it is far enough. Exact implementation is up to you. You could use something like a quad tree if you plan on moving on more than 1 axis (ie left-right, up-down).

Hope that helps.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .