My player HUD works perfect, but when I move, the monster name moves with me instead of getting attached to the monster.
Player has a HUD and I'm using Scene2D.ui
to pull it off and works great.
I use unit scale, that's why I got 2 camera. One for UI stuff and other for game.
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();
}
I'll appricate all kind of suggestions! If i could use Scene2D.ui for monsters aswell, would be great.
Cheers.
1 * world.unitScale
. Try do just doworld.unitScale
since multiplying by one does nothing anyways and might be converting your float to an integer. \$\endgroup\$