Well i think i’m on the right way. I’m using a second camera and font gets drawn right. But problem is that, if player moves, the text moves with him and do not stand still above monster head.
Orthogonal matrix is a projection matrix. It maps the screen coordinates you give (X 0-800, Y 0-600) to normalized unit coordinates (X 0-1, Y 0-1). This is for the OpenGL backend of libgdx. It makes it so 100 pixels is 100, not 100/800 or 100/600. (Assuming 800x600 screen)
Model-View matrix is a transformation matrix. Its a matrix made from the position, rotation, and the scale(size, 0 being virtually invisible). This is the base point of where the model would be - in this case a 2d square (two triangles). This doesn’t account for the size. If you were to draw all points of the square here, they would be in one corner of the triangle (the origin).
That is why you then transform from the origin to wherever the point needs to be. This is done per vertex (point). You multiply these 3 together in this order. OrthoMatrix * ModelMatrix * Vec3(offsetx,offsety,offsetz).
The Camera matrix, or whatever people want to call it, fits inbetween model and vertex offset. This is a further offset from the Model matrix. It allows to emulate the objects by offsetting them, for the fact there is not such thing as a camera in game programming. “move the world around instead of player”
… bottom line …
Make sure you have an ortho matrix, camera matrix, and a model matrix generated from the position, rotation, and scale. libgdx may do most of the work for you, so you should research more on libgdx in these areas - not necessarily matrix portion, but make sure something is happening to get the disired result.
I newer Used Libgdx ^^ - but i can show how it must be in layout
@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();
//Why? dublicate render
-- worldRenderer.render();
//this is painted in 2D - screen space - like GUI (inventory button etc)
//don't need change projection matrix you already in orthographics projection
//maybe need reset matrix to base - if Libgdx have same worlds matrix and GUI
-- Assets.font.draw(game.spriteBatch, "Firefox", uiPosition.x / 2, uiPosition.y / 2);
// Game GUI
++ GUI.draw();
}
//////
public worldRenderer.renderer.render(){
world.getPlayer().render();
for (Monster monster : world.getMonsters()) {
monster.render();
}
///Render Text - HP bars DMG numbers etc
//Don't need change camera matrix
world.getPlayer().render_Text(); // + y offset to be over Player head - "Player"
for (Monster monster : world.getMonsters()) {
monster.render_Text();// + y offset - "Firefox" (x,y = monster Position)
}
}
Because for some unknown reasons ppl that use Libgdx can’t answer
p.s Libgdx is not simple for beginners - maybe try RPG Maker, or Unity, Unreal
Thank you for your respone. About duplicate render, one is render the tiled map and another is rendrering creatures.
Without setting a new projection matrix, then the GUI stuff i render gets unit scaled, which is not ideal.
Then im back at square one. Where the name does not attach to the monster. If you read my first post, it will happen same thing. Also i’m share same batch with my hud.
"Fonts in libgdx are scaled in pixel dimensions and not your game world units. The best course of action here is to maintain two sperate cameras to render your game: world, and ui.
The world camera will be in your world units as you have it now. The ui camera will be in pixel units scaled to the game window. Use the project and unproject methods on the camera classes to position your ui elements correctly. Render the world using the world camera then do a ui pass over that with the ui camera."
My way is ideal, but i need help to setup it correctly.