How do I make an on-screen HUD in libgdx?
Posted
by
Devin Carless
on Game Development
See other posts from Game Development
or by Devin Carless
Published on 2012-06-29T20:51:53Z
Indexed on
2012/06/29
21:24 UTC
Read the original article
Hit count: 1708
libgdx
I'm new to libgdx, and I am finding I am getting stumped by the simplest of things. It seems to want me to do things a specific way, but the documentation won't tell me what that is.
I want to make a very simple 2d game in which the player controls a spaceship. The mouse wheel will zoom in and out, and information and controls are displayed on the screen.
But I can't seem to make the mouse wheel NOT zoom the UI. I've tried futzing with the projection matrices in between
Here's my (current) code:
public class PlayStage extends Stage {
...
public void draw() {
// tell the camera to update its matrices.
camera.update();
// tell the SpriteBatch to render in the
// coordinate system specified by the camera.
spriteBatch.setProjectionMatrix(camera.combined);
spriteBatch.begin();
aButton.draw(spriteBatch, 1F);
playerShip.draw(spriteBatch, 1F);
spriteBatch.end();
}
}
camera.zoom is set by scrolled(int amount).
I've tried about a dozen variations on the theme of changing the camera's projection matrix after the button is drawn but before the ship is, but no matter what I do, the same things happen to both the button and the ship. So:
What is the usual libgdx way of implementing an on-screen UI that isn't transformed by the camera's projection matrix/zoom?
© Game Development or respective owner