Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX - Set a background image ( to be static)

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

like image 807
julian Avatar asked Mar 15 '26 17:03

julian


1 Answers

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();
}
like image 186
Tomasz Gawel Avatar answered Mar 18 '26 06:03

Tomasz Gawel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!