So I am programming a 2D game in Java with LWJGL. I have my ortho camera in my gameloop and set it on the position I want to see. Now when I want to draw a HUD to show my money etc, I can either give it an absolute coordinate, so that it is part of my map and I can scroll away from my HUD (that definitely doesn't make sense for HUDs), or I can add my HUD vector to my cameras bottom-left Vector. Problem with that last solution is, that if I move my camera, my HUD does not perfectly update and you see it chasing its actual position.
So my question is: Is there any way I can set a fixed position relative to my screen in a second 'layer'? I've seen some people who only use gltranslate to move camera, but I guess it could be much work to change it now, so I'd like to keep my ortho camera.
edit:
This is what my Graphicsloop looks like and it still does not work properly:
private void updateRunning() {
cam.update();
drawEntities();
drawHud();
cursor.draw();
}
I can add my HUD vector to my cameras bottom-left Vector. Problem with that last solution is, that if I move my camera, my HUD does not perfectly update and you see it chasing its actual position.
That's not what should happen. What's likely happening is you have something like this:
gameLoop() {
update();
drawPlayer();
drawHud();
updateCamera();
}
However, you need to update the camera before drawing anything (or even before updating).
gameLoop() {
update();
updateCamera();
drawPlayer();
drawHud();
}
To draw the HUD on top of other objects, just render it after.
drawBackground();
drawPlayer();
drawHUD();