Jump to content

dxCreateFont doesn't work!


patriot

Recommended Posts

local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
local myFont = nil 
  
function createText ( ) 
    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. 
    myFont = dxCreateFont( "futurebq.ttf", 20 )  
    -- Draw zone name text's shadow. 
    if myFont then 
    dxDrawText (playerZoneName, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, myFont ) 
    -- Draw zone name text. 
    dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, myFont )  
    else 
    dxDrawText ( "failed to import font", 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" )  
    end 
end 
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) 

The "futurebq.ttf" is simply located at the same resource directory. Not sure why it isn't working. (myFont returns false)

Link to comment
local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height) 
local myFont = dxCreateFont( "futurebq.ttf", 20 ) 
  
function createText ( ) 
    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. 
    -- Draw zone name text's shadow. 
    if myFont then 
    dxDrawText (playerZoneName, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, myFont ) 
    -- Draw zone name text. 
    dxDrawText ( playerZoneName, 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, myFont ) 
    else 
    dxDrawText ( "failed to import font", 44, screenHeight - 43, screenWidth, screenHeight, tocolor ( 255, 255, 255, 255 ), 1, "pricedown" ) 
    end 
end 
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, createText ) -- keep the text visible with onClientRender. 
end 
  
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) 

Try that.

Link to comment

Another question:

How do I get the text to show at the center of ANY resolution?

Also, I tried to change the colorCode to true, but when I do this there is no text at all.

    dxDrawText(playerZoneName, 700, screenHeight - 41, screenWidth, screenHeight, 0xff0000, 1.02, myFont, "left", "top", true) 
    -- Draw zone name text. 
    dxDrawText ( playerZoneName, 700, screenHeight - 43, screenWidth, screenHeight, 0xff0000, 1, myFont, "left", "top", true 

As in the wiki:

bool dxDrawText ( string text, float left, float top [, float right=left, float bottom=top, int color=white,  
                  float scale=1, mixed font="default", string alignX="left", string alignY="top", 
                  bool clip=false, bool wordBreak=false, bool postGUI=false, 
                  bool colorCoded=false, bool subPixelPositioning=false ] ) 

Did I miss something?

Link to comment

To get it in the center, take in mind the following:

screenWidth,screenHeight=guiGetScreenSize(); 

The x-middle of the viewport is screenWidth / 2

The y-middle is screenHeight / 2

To get the element drawn on center, subtract the (element's width / 2) and height/2

also, because you're drawing text, make sure to set the alignment parameters to "center" and "center"

Tekening4.png

  
-- example from other topic 
-- viewtopic.php?f=91&t=50913 
  
x,y=guiGetScreenSize(); 
elementPositionX = x / 2 - 300 / 2; 
elementPositionY = y - 70; 
  
guiCreateLabel ( elementPositionX , elementPositionY , 300, 70, "at emt they serve it up", false ); 
  

Regarding the colour, you specified "0xff0000", which is not hexadecimal RGBA, but RGB. Use "0xffff0000" for opaque red or "0xff00000" for opaque black.

Link to comment

Thanks for the information, I appriciate it.

One question; what If I want to set static position for the dxText, let's say, not the center, but in the center of the bottom?

I want it to show at the center-bottom at any screen resolution, what should I use now?

Link to comment

Well, the text will be drawn 41 pixels above the border at the bottom of any screen resolution, so indeed, it's not the same:

For (1280)x720 it will be drawn at 679 px from the top and on (1440)x1080 it will be drawn at 1039px from the top.

This is the desired behaviour, right? That the text is drawn like the blue paint squiggle in the following image:

position.png

Link to comment

In your code, you put this:

dxDrawText(playerZoneName, 700, screenHeight - 41, screenWidth, screenHeight, 0xff0000, 1.02, myFont, "left", "top", true) 

Can you show me the code how you declare screenWidth and screenHeight? Or, if you put in static numbers (like screenWidth = 1280) then just replace those lines (for screenWidth and screenHeight) by the following:

screenWidth,screenHeight=guiGetScreenSize() 

If you already have this, then it should work already

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