drawing text on screen "over" an entity?

Blitz3D Forums/Blitz3D Beginners Area/drawing text on screen "over" an entity?

chwaga(Posted 2007) [#1]
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 :)


GfK(Posted 2007) [#2]
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.


puki(Posted 2007) [#3]
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.


Naughty Alien(Posted 2007) [#4]
one piece of advice..try to escape from B3D text command..instead use some extension libs or bitmap fonts..


chwaga(Posted 2007) [#5]
puki, the label isn't showing up...


Rob Farley(Posted 2007) [#6]
As Puki said http://www.blitzbasic.com/codearcs/codearcs.php?code=13
Does the job.

You need to remember you need to do this AFTER the renderworld but before the flip.

So you get

Repeat



UpdateWorld
Renderworld

[2D Text overlay stuff]

Flip
Until keyhit(1)


Canardian(Posted 2007) [#7]
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 :)