scienziato-pazzo Posted January 15, 2014 Share Posted January 15, 2014 Hi, I used dxCreateFont to use my custom font on the script. But how can I set the font-size depending on the screen resolution? Link to comment
Saml1er Posted January 16, 2014 Share Posted January 16, 2014 local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) function createText ( ) myFont = dxCreateFont( "segoeui.ttf", 20 ) -- dxCreateFont( "segoeui.ttf", FONT SIZE ) local playerX, playerY, playerZ = getElementPosition ( localPlayer ) -- Get our player's coordinates. local playerZoneName = getZoneName ( playerX, playerY, playerZ ) -- Get name of the zone the player is in. dxDrawText ( playerZoneName, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, myFont ) -- tocolor ( 0, 0, 0, 255 ), Font size, myFont ) dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, myFont) end function HandleTheRendering ( ) addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. end addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) Also add this line in your meta.xml. "segoeui.ttf" /> Link to comment
scienziato-pazzo Posted January 16, 2014 Author Share Posted January 16, 2014 local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) function createText ( ) myFont = dxCreateFont( "segoeui.ttf", 20 ) -- dxCreateFont( "segoeui.ttf", FONT SIZE ) local playerX, playerY, playerZ = getElementPosition ( localPlayer ) -- Get our player's coordinates. local playerZoneName = getZoneName ( playerX, playerY, playerZ ) -- Get name of the zone the player is in. dxDrawText ( playerZoneName, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, myFont ) -- tocolor ( 0, 0, 0, 255 ), Font size, myFont ) dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, myFont) end function HandleTheRendering ( ) addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. end addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) Also add this line in your meta.xml. "segoeui.ttf" /> Yes, but I use dxCreateFont to set the font-size, because if I set it in the dxDrawText function, the font is different. Link to comment
Gallardo9944 Posted January 16, 2014 Share Posted January 16, 2014 myFont = dxCreateFont( "segoeui.ttf", 20 ) This one creates a font where scale of 1 will make it use 20 PTs size. Change 20 to any other value to use as a scale of 1, change the scale to make it change the size without touching the font. Link to comment
Enkanet Posted October 3, 2015 Share Posted October 3, 2015 local screenW, screenH = guiGetScreenSize() local fontSize = math.ceil((defaultFontSize * screenW) / (defaultScreenWidth * 1.0)) local myFont = dxCreateFont( "segoeui.ttf", fontSize ) Default Font Size should be the font size on your screen. Example, you designed it in 20pt on your screen, then write 20. Default Screen Width is screen width of your resolution. Example your resolution is 1366*768 then default screen width should be 768. Cheers. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now