Libgdx how to display monster name above their head

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.

draw the name in the monster´s render function not in the hud then it should be fine

Well that would work if i was not using unit scale :-\

Also wanna Thank you for trying to help me, really appricate it :slight_smile:

font.setScale(w.e. you use);
draw name
font.setScale(1); //reset

Sorry, but this did not work. I scaled it down as much as possible, but the font gets disorted and does not display whole name:

http://1.1m.yt/N8CazFU.png

Don’t try zoom font) its 2d - create new one with prefer size 8-14 ttf

"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.

It’s not )
(becouse you scale texture of font Atlas)
wrong stackexchange answer ^^


//
right one

Or use official doc

But if it’s not ideal, then how will i draw health bar at unit scale aswell?

Create 5-10 fonts that you needed

  • they all have same img quality as you create them, if you not try to scale them.

If you have in game zoom and wants to zoom in-out camera with font zoom

you can scale font texture – for 10-20% its ok, but on 200-300% it looks terrible
so you can swap on bigger/smallest Texture font
//
or try use https://github.com/libgdx/libgdx/wiki/Distance-field-fonts

up:

Maybe you could try setting the camera’s zoom and reset it after you draw the name

Sorry but this did not work, as i said. Unit scale is a ridiculous size to scale down to. So thats why i need to seprate the ui stuff from the world stuff.

http://4.1m.yt/x2F5VhA.png

You do something totally wrong
You have pixel ground tiles – let say 32 x 32 pixels you draw them
No zoom – scale needed
Then you draw Npc – trees etc – also pixels 1:1
No zoom – scale needed

But when you try draw text above world – you’r text is scaled from nowhere
And looks totally wrong

Well when i draw the sprites i set height and width multiply with unit scale (1 / 32f) but when i scale font, it looks really bad.

[quote=“Icecore,post:33,topic:57338”]
You do totally wrong
No zoom – scale needed :wink:

I got it working :slight_smile:

By setting Assets.font.getCache().setUseIntegerPositions(false); now it setScale propely. But i wonder, when i have alot of monster on my screen and drawing the monster font. It decrease my FPS alot. Any suggestions about that? Also if i would like to add progress bar, how should i scale that? Since it does not have the same option as font.

Thanks for all your help mate!

Need Draw names to texture (Cache) and then draw only 1 texture above monster not 10 draw calls for every character in name

That why you don’t need use scale in 2d games at all - so everything be same - predictable size
(except global zoom , or some Effects scale like laser)

No problem :wink:

p.s Realy go check and try Unity . Unreal
This problems you have now is only drop in the ocean, you be forced of thousands new ones(engine problems)

Well i used scale due to player offset from it’s position.

I want to use Java, that why i’m using Libgdx and not Unity :slight_smile:

glTranslate != glScale
Move Camera != Scale it

you use scale wrong - simple remove it from game.
And all be ok: all textures & fonts - be nice and pretty.

For the graphics we need to define a target resolution of 800x480 pixels (landscape mode on Android). If the device the game is run on does not have that resolution, we simply scale everything to fit on the screen. Note: for high profile games you might want to consider to have different assets for different screen densities. This is a big topic on its own and won’t be covered here.

You must Use only Global scale not per random element you want
(because you have no idea how scale works ^^ - Scale always destroy pixels: if in 3D its Ok - for pixel games its nightmare)

You need read many more tutorials in google and Gamedev books to at least understand basics
I really can’t answer on every you’r question (problem) :wink: