I explain what i’m trying to do,
I just want to draw a text up the head of my player. So i tryed with the bitmapFont(), with an x, y, z position, but there’s nothing drawing at this position.
It only work with a X,Y position and it follow the camera…
After searching the forum, and the docs, i don’t find any way to draw a text in a spatial environement.
Maybe someone can help me about it ?
Thanks in advance.
Just add a BitmapText to the gui node and set the location based on the screen coordinates of the player / head (similar to picking)
Take a look at TestBillboard.java in jme3test:model.shape if you want text above the player which always faces the camera
I tried this with a bitmapText :
BitmapFont guiFont = game.getAssetManager().loadFont(“Interface/Fonts/Default.fnt”);
BitmapText helloText = new BitmapText(guiFont, false);
helloText.setLocalTranslation(-140, 10, -10);
but at the position -140 10 -10 (which is exactly the same position of my Player), there’s nothing appearing :s…
Your position is applied in the guiNode space, which is definately not in world space.
To obtain the correct position, try something like this:
[java]helloText.setLocalTranslation(cam.getScreenCoordinates(playerNode.getLocalTranslation().add(0, heigthAbovePlayer, 0)));[/java]
so, i have to add my bitmapFont to the rootNode ?
In your current way of trying it, not really.
You add your bitmapFont to the guiNode, you just have to tell your bitmapFont where to be in the guiNode on every update. In order to obtain the right position to do this (as you need to go from 3d space to 2d on your screen) you have to get the screen coordinates for the 3d position everytime by asking the camera what the given 3d position is in the 2d space.
Another way to obtain nearly the same result would be to add a billboard node to your playerNode, als @nego suggested. The main difference will be wether the text is drawn on top of everything (as is right now) or can be obstructed by say, a tree or a wall (using the billboard).