Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I draw background tile in my 2D side-scrolling game? Is that loop logical for OpenGL es? My tile 2400x480. Also I want to use parallax scrolling for my game.

for(int i=0; i<100; i++)
    batcher.drawSprite(0+2400*i, 240, 2400, 480, Assets.backgroundRegion);



And thats my onDrawFrame.I'm sending deltaTime for fps control.

public void onDrawFrame(GL10 gl) {                
    GLGameState state = null;

    synchronized(stateChanged) {
        state = this.state;

    if(state == GLGameState.Running) {
        float deltaTime = (System.nanoTime()-startTime) / 1000000000.0f;
        startTime = System.nanoTime();


    if(state == GLGameState.Paused) {
        synchronized(stateChanged) {
            this.state = GLGameState.Idle;

    if(state == GLGameState.Finished) {
        synchronized(stateChanged) {
            this.state = GLGameState.Idle;
share|improve this question
Are you not getting the results you want with your current code? What have you tried already? What about it isn't working? – Byte56 Apr 10 '12 at 23:50
@Byte56 i think thats not logical.Because i draw background already for 2400*100 pixels.I'm searching for better idea. – droidmachine Apr 11 '12 at 7:00
In android sample application Lunar Lader they have explain how to move background of a game. Using that sample, this article explain this concept very well – TofeeqAhmad Dec 26 '12 at 5:15
up vote 2 down vote accepted

In this code, you are drawing the background 100 times in 100 different places in 1 frame. Learn how to properly use a game loop to run your game (here's a good article: Your going to want to update the background's position in each update tick of your game loop and draw it at its current location in each frame.

Post-Update Edit: So in screen.update(deltaTime); you'll want to change the current background position with something like:
background.translate(BACKGROUND_SCROLL_SPEED * deltaTime, 0)

Then, in screen.present(deltaTime); draw the background with: batcher.drawSprite(background.getX(), 240, 2400, 480, Assets.backgroundRegion);

Let me know if you still have questions.

share|improve this answer
i'm using a different game loop already in my upper class.Are there any other solution for this? – droidmachine Apr 11 '12 at 7:03
What does your game loop look like? Because you need to be changing the position in the update section and drawing it in its current position in the draw section. This is the best (and pretty much only) way to make real-time games. If you edit your question to show what your game loop looks like, I will help you understand how to do this. – Amplify91 Apr 11 '12 at 10:00
I have updated my question. – droidmachine Apr 11 '12 at 12:19
@droidmachine I updated my answer. – Amplify91 Apr 12 '12 at 2:12
I have used this but no solution: in update(): backx+=200*deltaTime; in present(): batcher.drawSprite(backx, 240, 2400, 480, Assets.backgroundRegion); – droidmachine Apr 12 '12 at 15:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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