Jump to content

[HELP] dxGetTextWidth problem


Recommended Posts

I want to put a picture before players name in their nametag, and with a longer name fits well, but no with a sorter...

What is the problem? 

Code:

local width, height = (dxGetTextWidth(getPlayerName(v),1,settings.font,true)+270)*scale, 2*scale

a picture of the problem:

spacer.png

Link to post
  • Moderators
8 hours ago, Turbesz said:

What is the problem? 

What about

dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale

-- or if the font is scaled:

dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale

for the width.

  • Thanks 1
Link to post
45 minutes ago, IIYAMA said:

What about


dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale

-- or if the font is scaled:

dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale

for the width.

thank youuu so much :D

  • Like 1
Link to post
1 hour ago, IIYAMA said:

What about


dxGetTextWidth(getPlayerName(v), 1,settings.font,true) + 270 * scale

-- or if the font is scaled:

dxGetTextWidth(getPlayerName(v), scale,settings.font,true) + 270 * scale

for the width.

umm, another little problem. if i want to put another image after the player's name, again the same problem just in the other direction. with this code:

local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale

 

Link to post
  • Moderators
24 minutes ago, Turbesz said:

umm, another little problem. if i want to put another image after the player's name, again the same problem just in the other direction. with this code:

Normally you would calculate the position like this:

-- The width
local textWidth = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) 

local offset = scale * 50 -- Offset from the text


-- Note: The text is centered!!!

local positionX

-- Before
positionX = positionX - (textWidth / 2 + offset)

-- After
positionX = positionX + (textWidth / 2 + offset)

 

 

 

Link to post
19 minutes ago, IIYAMA said:

Normally you would calculate the position like this:


-- The width
local textWidth = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) 

local offset = scale * 50 -- Offset from the text


-- Note: The text is centered!!!

local positionX

-- Before
positionX = positionX - (textWidth / 2 + offset)

-- After
positionX = positionX + (textWidth / 2 + offset)

 

 

 

then if I understand correctly i have to change 'sx' to 'positionX' in my code?

local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad")
local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale
local sx, sy = sx-width/2, sy-height	
dxDrawImage(sx, sy, 40, 40, "files/typing.png",0,0,0,tocolor(255,181,64,255))

 

Link to post
  • Moderators
1 hour ago, Turbesz said:

local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad") local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true) - 350 * scale, 2*scale local sx, sy = sx-width/2, sy-height dxDrawImage(sx, sy, 40, 40, "files/typing.png",0,0,0,tocolor(255,181,64,255))

 

An example:

local scale = interpolateBetween(0.7, 0, 0, 0, 0, 0, progress, "OutQuad")

local width, height = dxGetTextWidth(getPlayerName(v),scaleF,settings.font,true), 2*scale


local imageSize = 40 * scale
local offset = 40 * scale

local sx, sy = sx - (width / 2 + imageSize + offset), sy-height	

dxDrawImage(sx, sy, imageSize, imageSize, "files/typing.png",0,0,0,tocolor(255,181,64,255))



-- no imageSize since the image is drawn from left to right
local sx, sy = sx + (width / 2 + offset), sy-height	

dxDrawImage(sx, sy, imageSize, imageSize, "files/typing.png",0,0,0,tocolor(255,181,64,255))

 

Anyway, I am wondering why you use the value '350'. The image was only 40 pixels and unscaled.

 

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...