Jump to content
  • Advertisement
Sign in to follow this  
X5-Programmer

Print character names.

This topic is 5016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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-padding

Position is the middle of the player:
x =GetPlayerX()-TextWidth*0.5
y =GetPlayerY()-PlayerHeight*0.5-TextHeight-padding

If 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!