Jump to content

[HELP] Dxdrawtext question...


Turbesz

Recommended Posts

I wrote two texts with dxdrawtext and with same calculations for all resolution

and one text is in the right place but another is not with same method... 

wth? anyone can help me?

code:

local sx, sy = guiGetScreenSize()

function draw()
dxDrawText("#FFB540Test text test text test text test text", sx/2-140-10,sy/2-320/2, 0, sy/2-515/2+36, tocolor(255,255,255,255), 1, Roboto, "left", "center",false,false,false,true)
dxDrawText("text2 text2 text2 text2 text2 text2 text2 text2", sx/2+890-10,sy/2+940/2, 0,sy/2-515/2+36, tocolor(255,255,255,255), 1, Roboto, "center", "center",false,false,false,true)
end
addEventHandler("onClientRender",root,draw)

the text with colorcode it is in a good place on every resolution but "text2" moves in another resolutions... why?

Edited by Turbesz
Link to comment
local sx, sy = guiGetScreenSize()

function draw()
	dxDrawText("#FFB540Test text test text test text test text", sx/2-140-10,sy/2-320/2, 0, sy/2-515/2+36, tocolor(255,255,255,255), 1, Roboto, "left", "center",false,false,false,true);
	local text = "text2 text2 text2 text2 text2 text2 text2 text2"; --define text
	local textSize = dxGetTextWidth(text, 1, Roboto, true); -- get the width of the text; 
	local fontHeight = dxGetFontHeight(1, Roboto); -- get the height of the text;
	dxDrawText(text, sx/2-textSize/2, sy/2-fontHeight/2, sx, sy, tocolor(255,255,255,255), 1, Roboto, "center", "center",false,false,false,true);
  	--draw the text in the middle of the screen!
end
addEventHandler("onClientRender", root, draw);

You might do the same for the first one, just keep in mind the text align works like this (X + TEXT WIDTH) :)

Link to comment
13 hours ago, Tekken said:

local sx, sy = guiGetScreenSize()

function draw()
	dxDrawText("#FFB540Test text test text test text test text", sx/2-140-10,sy/2-320/2, 0, sy/2-515/2+36, tocolor(255,255,255,255), 1, Roboto, "left", "center",false,false,false,true);
	local text = "text2 text2 text2 text2 text2 text2 text2 text2"; --define text
	local textSize = dxGetTextWidth(text, 1, Roboto, true); -- get the width of the text; 
	local fontHeight = dxGetFontHeight(1, Roboto); -- get the height of the text;
	dxDrawText(text, sx/2-textSize/2, sy/2-fontHeight/2, sx, sy, tocolor(255,255,255,255), 1, Roboto, "center", "center",false,false,false,true);
  	--draw the text in the middle of the screen!
end
addEventHandler("onClientRender", root, draw);

You might do the same for the first one, just keep in mind the text align works like this (X + TEXT WIDTH) :)

thanks, but i don't want to place it in the middle of the screen, I want put in the middle of a button. The first one is is in a perfect place, but the second one not (at my resolution yes, but other resolutions not, because moves, the first one doesn't do that). 

Link to comment

A little example

local sx, sy = guiGetScreenSize();
local scaleX,scaleY = 1920/sx, 1080/sy; -- replace 1920 and 1080 with your resolution!

function draw()
	-- Let's say we want to create a button on the right side 20px away from the screen at 150px from the bottom;
  	local xpos = 20*scaleX;
  	local ypos = 150*scaleY;
	local text = "PRESS ME!";
	local tx, ty = dxGetTextSize(text, 0, 1, 1, Roboto, true);
	dxDrawText(text, sx-tx-xpos, sy-ty-ypos, sx-xpos, sy-ypos, tocolor(255,255,255,255), 1, Roboto, "center", "center", false, false, false, true);
end
addEventHandler("onClientRender", root, draw);

 

Take a look at this tutorial:

Hope that helped you! :)

 

  • Like 1
Link to comment
On 07/02/2021 at 09:53, Tekken said:

A little example


local sx, sy = guiGetScreenSize();
local scaleX,scaleY = 1920/sx, 1080/sy; -- replace 1920 and 1080 with your resolution!

function draw()
	-- Let's say we want to create a button on the right side 20px away from the screen at 150px from the bottom;
  	local xpos = 20*scaleX;
  	local ypos = 150*scaleY;
	local text = "PRESS ME!";
	local tx, ty = dxGetTextSize(text, 0, 1, 1, Roboto, true);
	dxDrawText(text, sx-tx-xpos, sy-ty-ypos, sx-xpos, sy-ypos, tocolor(255,255,255,255), 1, Roboto, "center", "center", false, false, false, true);
end
addEventHandler("onClientRender", root, draw);

 

Take a look at this tutorial:

Hope that helped you! :)

 

thanks

Link to comment

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...