Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Centering Player Name (100% accurate)
#1
Centering Player Name (100% accurate)
[Difficulty: 1/5] (Copy-Paste)

Basically this tut will show you how to use the call GetTextExtentPoint32 to find the width of the name and then how to encorporate it into the sub BltPlayerName.

ALL CLIENTSIDE:
In modDeclares, add this:
Code:
Public Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hDC As Long, ByVal lpszString As String, ByVal cbString As Integer, ByRef lpSize As Size) As Integer
*note ~ I set this to integer because I dont need to find the length of anything more than 255 chars

In modTypes, add this:
Code:
Type Size
cx As Long
cy As Long
End Type
This creates the type Size which GetExtentPoint32 needs to dump the text info

Now go to BltPlayerName and add these at top:
Code:
Dim textSize As Size
Dim textWidth As Integer

Under the color assigns, add this:
Code:
'measure width of name
    SelectObject TexthDC, GameFont
    GetTextExtentPoint32 TexthDC, GetPlayerName(Index), Len(GetPlayerName(Index)), textSize
    textWidth = textSize.cx
This gets the size info for your name and assigns the width to textWidth

Now replace:
Code:
TextX = GetPlayerX(Index) * PIC_X + Player(Index).XOffset + Int(PIC_X / 2) - ((Len(GetPlayerName(Index)) / 2) * 8)
With:
Code:
TextX = (GetPlayerX(Index) * PIC_X) + (Player(Index).XOffset) + (Int(PIC_X / 2)) - (Int(textWidth / 2))
This changes the old x coordinate assign to center the text with the new info.

And you're done! You can apply this to NPC names, the map name, and whatever else you want to center.
Reply
#2
screens pl0x!
Reply
#3
*Bump and image of working example

[Image: centeredname.png]
Reply
#4
Doesn't look centered to me..
Reply
#5
It's not 100% centered, but at least you know it's always gonna be fairly consistent.
Reply
#6
Not really. I've been using this function for a long time and it's very temperamental.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Reply
#7
hey 32px on the left, 30 px on the right. but the sprite is 1 px to the right anyways (19px wide), that is centered to me ;P
Reply
#8
seraphelic Wrote:hey 32px on the left, 30 px on the right. but the sprite is 1 px to the right anyways (19px wide), that is centered to me ;P

Regardless if it's center to you or not, it's not 100% centered.

Tongue

Which is what you claim with this. So, you're wrong. ^_^
Reply
#9
You know, I could swear the tutorial used to say 95% accurate
Reply
#10
thats because i was using a different method because i couldnt get GetTextExtentPoint32 to work. My source renders the map name and player name perfectly centered, ive tested 7pt, 8pt, 9pt, and 10pt with tahoma, verdana, and a couple others.
Reply
#11
works perfectly for me ^^

looks absolutely fantastic finally names will look correct to me.

A very nice tut mate well done :mrgreen:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)