Question

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

Was it helpful?

Solution

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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top