LibGDX - Set a background image ( to be static)

2.1k views Asked by At

I set the background image like this -

batch.draw(Assets.back_sprite, 0, 0, ResX, ResY);

The problem is when i move the camera -

camera.translate(2,0);

The image starting to move backwards and eventually disappears, because I drew it at (0,0)
and the camera is moving in a speed of (2,0), that's why the the image goes away.

  • The camera is ortho not perspective.

How can i make the image to be static and always stay there? Any ideas?

Thanks in advance :P

1

There are 1 answers

0
Tomasz Gawel On BEST ANSWER

Render it with another camera

OrthographicCamera mStageCamera;
OrthographicCamera mFixedCamera;
SpriteBatch mBatch;

@Override
public void render() {
    mBatch.setProjectionMatrix(mFixedCamera.combined);
    mBatch.begin();
    //render "static" elements
    mBatch.end();

    mBatch.setProjectionMatrix(mStageCamera.combined);
    mBatch.begin();
    //render "movable" elements
    mBatch.end();
}