Hello,
It has been days for trying and failing to pull this off. Also asked for help, but seems none can help me either.
I were able to create HUD for the player, that was really easy. But then i got stuck about creating HUD for the monsters. Such as i want to draw their name above the head and also maybe add a health bar aswell.
As you see, the player hud works perfect, but when i move the monster name moves with me. Instead to get attached to the monster.
public void update(float deltaTime) {
// update creatures
world.getPlayer().onThink(deltaTime);
for (Monster monster : world.getMonsters()) {
monster.onThink(deltaTime);
}
// update camera to the player
camera.position.set(world.getPlayer().getPosition(), 0);
camera.update();
}
@Override
public void render(float deltaTime) {
// clear screen
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// seprate update logic
update(deltaTime);
// set camera to what we see
worldRenderer.renderer.setView(camera);
worldRenderer.renderer.render();
// draw world
game.spriteBatch.setProjectionMatrix(camera.combined);
worldRenderer.render();
// monster UI
game.spriteBatch.setProjectionMatrix(uiCam.combined);
for (Monster monster : world.getMonsters()) {
uiCam.project(uiPosition.set(monster.getPosition().x, monster.getPosition().y, 0));
}
game.spriteBatch.begin();
Assets.font.draw(game.spriteBatch, "Firefox", uiPosition.x / 2, uiPosition.y / 2);
game.spriteBatch.end();
// Player Hud
game.spriteBatch.setProjectionMatrix(hud.stage.getCamera().combined);
hud.stage.draw();
}
Thanks!