Jump to content

dxCreateFont relative size


Recommended Posts


How do calculate relative size for dxCreateFont?

local font = dxCreateFont("bankgothic",20) 
dxDrawText("starting next map:", sx*(291/1024),  sy*(598/768),sx*( 594/1024),  sy*(620/768), tocolor(175, 58, 196, 255),sx*(1/1024),font, "left", "top", false, false, true, false, false) 

Link to comment

How am I suppose to use it?

local font = dxCreateFont("bankgothic",20) 
local txt = "starting next map:" 
dxDrawText(txt, sx*(291/1024),  sy*(598/768),sx*( 594/1024),  sy*(620/768), tocolor(175, 58, 196, 255),dxGetTextWidth(txt,sx*(1/1024), font),font, "left", "top", false, false, true, false, false) 

EDIT: I just don't understand how to calculate relative size for dxCreateFont. Maybe this? https://wiki.multitheftauto.com/wiki/DxGetFontHeight

Link to comment
  • Moderators

Well that depends on your intentions.

The function dxGetTextWidth will might be handy to make something fit inside a rectangle.

But the relative size DxGetFontHeight might do it, but because it is a custom font I am not sure if the result will be correct.

The best thing you can do is draw the text and make a screenshot of it. Use photoshop to check how much pixels high it is and in the end you can calculate the relative size. So yes the font height is the solution, but I will recommend you to try both ways.

Link to comment
local x,y = guiGetScreenSize() 
local scale = 2 
local maxW = x*0.103 
function callBackMe3() 
local text = "WAITING FOR PLAYERS.." 
local w = dxGetTextWidth(text, scale, "arial") 
local scale = scale 
if w > maxW then 
callMe3 = setTimer(function() 
scale = scale - 0.01 
end, 50, 0) 

Takes some time to actually load if the resolution is small, and it isnt guaranteed to work in extrememly large resolutions. Other than that, flawless.

If you're bored, make it onClientRender re-sizing. will be much faster. But anyways..

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