Print character names.

Started by
5 comments, last by X5-Programmer 19 years, 3 months ago
Hi there, I just wonder how do they print the names over the characters in rpg games? let say I print the text like this.

for(itr = m_players.begin(); itr != m_players.end(); itr++)
{
	x = itr->GetPlayerX() / 2;
	y = itr->GetPlayerZ() / 2;
	glPrint(x, y, itr->GetName());
}

I dont know exacly how to do this, But I want to print names for eatch player in the m_players over the character. How do you guys do this? hope anyone can point me to a good solution. thanks.
-[ thx ]-
Advertisement
what about glRasterPos2X and glBitmap?
Its not that, I can print the font I only whant to know how to calc the x,y for the text using player x,z to get the name over the players.
-[ thx ]-
Well you want the y co-ordinate to be that of the player minus their height, & minus again the height of the text, minus some padding as well (that's if -y is up)
You also want some kind of function to tell you the width of the text in advance, then subtract half of that from the x to center it about a point.
If the x marks the center of the player then use that (minus half the text width)
If it marks the x then first add half the player width then subtract half the text width (then minus half the text width)
Try to get some paper to sketch this & see if you can "see" it
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
I dont understand exacly what you mean, but something like this?

y = ((GetPlayerY() - SCREEN_HEIGHT) - TextHeight);
x = ((SCREEN_WIDTH/2 - TextWidth/2) + (GetPlayerX()/2 / TextWidth/2) - TextWidth/2));

im not that good at english.

correct me.
-[ thx ]-
Okay well it depends what the position of the player actually means. I shall give 2 examples:

padding=LineHeight*0.5 (just to move it away from the head alittle)Position is the bottomleft corner of the player:  x =GetPlayerX()+PlayerWidth*0.5-TextWidth*0.5  y =GetPlayerY()-PlayerHeight-TextHeight-paddingPosition is the middle of the player:  x =GetPlayerX()-TextWidth*0.5  y =GetPlayerY()-PlayerHeight*0.5-TextHeight-paddingIf up is +y then change the - in the y formula to a +if(up==+1)formula.y.replace('-','+');

I hope that's easier to understand
_______________________________ ________ _____ ___ __ _`By offloading cognitive load to the computer, programmers are able to design more elegant systems' - Unununium OS regarding Python
PlayerHeight

The height the player pos on the map?
or height of the player model?
-[ thx ]-

This topic is closed to new replies.

Advertisement