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

有帮助吗?

解决方案

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();
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top