patriot Posted December 22, 2012 Share Posted December 22, 2012 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
Castillo Posted December 22, 2012 Share Posted December 22, 2012 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
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 Still doesn't work, myFont returns false. Anyone? Link to comment
uhm Posted December 23, 2012 Share Posted December 23, 2012 did you include it in meta.xml? <file src="futurebq.ttf" /> also Castillo's way of creating before and not within the onClientRender event is preferable performance wise Link to comment
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 Silly me. It works now, thanks! Link to comment
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 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
uhm Posted December 23, 2012 Share Posted December 23, 2012 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" -- 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
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 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
uhm Posted December 23, 2012 Share Posted December 23, 2012 Then you would use what you already had for the top-position (y-position) parameter: e.g. screenHeight - 41 Link to comment
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 But "screenHeight - 41" is not the same for 1280x720 and, for example 1440x1080, am I right? It's simply 720 minus 41 (as for 1280x720) and 1080 minus 41 (as for 1440x1080) or I completely misunderstood? Link to comment
uhm Posted December 23, 2012 Share Posted December 23, 2012 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: Link to comment
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 Yes, exactly. How can I do this? Link to comment
uhm Posted December 23, 2012 Share Posted December 23, 2012 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
patriot Posted December 23, 2012 Author Share Posted December 23, 2012 A'lright, I did the trick. However, I am still not sure if I am going to see the same relative position at any smaller / larger screen resolution. 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