I've seen in several games the displaying of text above entities (over their head) labelling them. How could i do this? (Also, I would like to draw it only if the entity is in view {entityinview command? there is one if i am not mistaken, how to use?})
thanks :)
You need to use CameraProject with your entity first, then ProjectedX and ProjectedY to determine where to draw your text.
There is an EntityInView function. I won't waste my/your time explaining it because the documentation explains it all well enough.
Function LabelEntity (camera, entity, label$)
If EntityInView (entity, camera)
CameraProject camera, EntityX (entity), EntityY (entity), EntityZ (entity)
w = StringWidth (label$)
h = StringHeight (label$)
x = ProjectedX () - (w / 2) - 1
y = ProjectedY () - (h / 2) - 1
Color 0, 0, 0
Rect x, y, w + 2, h + 2, 1
Color 255, 255, 255
Text x, y, label$
EndIf
End Function
This is the sort of thing.
one piece of advice..try to escape from B3D text command..instead use some extension libs or bitmap fonts..
puki, the label isn't showing up...
As Puki said
http://www.blitzbasic.com/codearcs/codearcs.php?code=13Does the job.
You need to remember you need to do this AFTER the renderworld but before the flip.
So you get
Repeat
[Game Loop]
UpdateWorld
Renderworld
[2D Text overlay stuff]
Flip
Until keyhit(1)
I would just write the text in a texturebuffer, and map the texture to a little cube and make the cube child of the player object, so it automatically stays over the players head when the player moves. You might still need to turn the text-cube towards the camera, unless you want real-life style text labels over the players heads :)