How do I draw a scrolling background?

Posted by droidmachine on Game Development See other posts from Game Development or by droidmachine
Published on 2012-04-10T23:44:28Z Indexed on 2012/04/11 17:42 UTC
Read the original article Hit count: 216

Filed under:
|

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.

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

batcher.endBatch();

UPDATE

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();

        screen.update(deltaTime);
        screen.present(deltaTime);
    }

    if(state == GLGameState.Paused) {
        screen.pause();            
        synchronized(stateChanged) {
            this.state = GLGameState.Idle;
            stateChanged.notifyAll();
        }
    }

    if(state == GLGameState.Finished) {
        screen.pause();
        screen.dispose();
        synchronized(stateChanged) {
            this.state = GLGameState.Idle;
            stateChanged.notifyAll();
        }            
    }
}   

© Game Development or respective owner

Related posts about android

Related posts about opengl-es