Jump to content

Text under image how fix it ?


JoZeFSvK

Recommended Posts

Hey i have text and image but text is under image how i fix it ?

Part of text

dxDrawText(cashCL, x-750, 735, x-100, y, tocolor(102,135,255,200), 1.5, "default-bold", "left", "top")   
  

Part of image

dxDrawImageSection (325, screenHeight - 37, 64, 32, 131, 37, 64, 32, imgFile) --bg 
  

Where will problem who know ?

Link to comment

Its long

First

local x,y = guiGetScreenSize() 
  
local showAnim1 = 0 
local showAnim2 = 0 
  
local alpha1 = 200 
local alpha2 = 200      
  
local size1 = 0.75 
local size2 = 0.75    
  
local yup1 = 0      
local yup2 = 0    
  
local p = 0 
local c = 0 
  
function destroyAnim1() 
   showAnim1 = 0 
   size1 = 0.75 
   alpha1 = 200 
   yup1 = 0   
end 
function destroyAnim2() 
   showAnim2 = 0 
   size2 = 0.75 
   alpha2 = 200 
   yup2 = 0   
end 
  
addEventHandler("onClientPreRender", getRootElement(), function()  
  
   local pointsCL = 0 
   local cashCL = 0 
   local HPCL = 0 
  
   if (getElementData(getLocalPlayer(),"Points") ~= false) then 
      pointsCL = getElementData(getLocalPlayer(),"Points") 
   end 
   if (getElementData(getLocalPlayer(),"Cash") ~= false) then 
      cashCL = getElementData(getLocalPlayer(),"Cash") 
   end 
   if (getPedOccupiedVehicle(getLocalPlayer()) ~= false) then 
      HPCL = math.round ( getElementHealth ( getPedOccupiedVehicle(getLocalPlayer()) ), 0) 
   else 
      HPCPL = 0 
   end 
  
   if (p ~= pointsCL) then 
      showAnim1 = 1 
      p = pointsCL 
   end 
  
   if (c ~= cashCL) then 
      showAnim2 = 1 
      c = cashCL 
   end 
  
   dxDrawRectangle ( x-300, 50, 250, 40, tocolor(0, 0, 102, 200) )  
   dxDrawText("Let's Derby", x-300, 50, x-50, 90, tocolor(255, 255, 255, 200), "2", "arial", "center", "center")  
  
   dxDrawRectangle ( x-300, 90, 250, 110, tocolor(0, 0, 0, 64) )  
  
   dxDrawLine(x-299, 90, x-299, 90+110, tocolor(0, 0, 102, 200), 2) 
   dxDrawLine(x-51, 90, x-51, 90+110, tocolor(0, 0, 102, 200), 2) 
  
   dxDrawText("POINTS", x-290, 95, x, y, tocolor(255,255,255,200), 0.75, "bankgothic", "left", "top") 
  
  
  
----------------------------------------------------------- 
   dxDrawText(pointsCL, x-290, 95, x-60, y, tocolor(245,184,0,200), 0.75, "default-bold", "left", "top") 
----------------------------------------------------------- 
  
  
   dxDrawText("CASH", x-290, 115, x, y, tocolor(255,255,255,200), 0.75, "bankgothic", "left", "top")  
  
  
------------------------------------------------------------- 
   dxDrawText(cashCL, x-740, 735, x-100, y, tocolor(102,135,255,200), 1.5, "default-bold", "left", "top")  -- THIS I EDIT POSITION 
------------------------------------------------------------- 
--x290,115,x-60,y               0.75 velkost pisma 
--doprava,dole,asinic, 
  
  
  
  
   dxDrawLine(x-299, 145, x-51, 145, tocolor(0, 0, 102, 200), 2) 
  
   dxDrawText("Health", x-290, 150, x, y, tocolor(255,255,255,200), 0.75, "bankgothic", "left", "top") 
  
    local health = HPCL 
    health = math.max(health - 250, 0)/750 
    local p = -510*(health^2) 
    local r,g = math.max(math.min(p + 255*health + 255, 255), 0), math.max(math.min(p + 765*health, 255), 0) 
    dxDrawRectangle (x-160,  
                        157,  
                        100,  
                        10,  
                        tocolor(r,g,0,50)  
                    ) 
    --Finally, the actual health 
    dxDrawRectangle (x-160,  
                        157,  
                        health*(100),  
                        10,  
                        tocolor(r,g,0,150)  
                    ) 
  
   dxDrawLine(x-299, 200, x-51, 200, tocolor(0, 0, 102, 200), 2) 
   dxDrawText("Speed", x-290, 170, x, y, tocolor(255,255,255,200), 0.75, "bankgothic", "left", "top")   
  
   if (showAnim1 == 1) then           
        dxDrawText(pointsCL, x-290, 95-yup1, x-60, y, tocolor(245,184,0,alpha1), size1, "bankgothic", "right", "top")            
      size1 = size1 + 0.04 
      yup1 = yup1 + 0.75 
      if (alpha1 > 3) then  
         alpha1 = alpha2 - 2  
      else 
         destroyAnim1() 
      end        
   end  
   if (showAnim2 == 1) then              
        dxDrawText(cashCL, x-290, 115-yup2, x-60, y, tocolor(102,140,255,alpha2), size2, "bankgothic", "right", "top")         
      size2 = size2 + 0.04  
      yup2 = yup2 - 0  
      if (alpha2 > 3) then  
         alpha2 = alpha2 - 2  
      else 
         destroyAnim2() 
      end      
   end 
    
           
end 
) 

and

local screenWidth,screenHeight = guiGetScreenSize() 
local owlsFont = dxCreateFont( "files/fonts/font.ttf", 24 ) 
local spriteFile = "files/images/img.png"  
function mainDrawing () 
    local ping = getPlayerPing(getLocalPlayer()) 
    local alivePlayers = getAlivePlayers() 
--Backgrounds 
    dxDrawImageSection (screenWidth - 125, screenHeight - (screenHeight - 10), 128, 64, 1, 287, 128, 64, spriteFile) 
  
dxDrawImageSection (261, screenHeight - 37, 64, 32, 195, 37, 64, 32, spriteFile)--Cash bg -- HERE 
-- vyska,roztiahnutie,natiahnutie, hmmm,horedole, 
  
    dxDrawImageSection (325, screenHeight - 37, 64, 32, 131, 37, 64, 32, spriteFile)--Points bg 
 -- Text time 
    dxDrawText (getServerTime()[2], screenWidth - 42, screenHeight - (screenHeight - 33), screenWidth - 12, screenHeight - (screenHeight - 67), tocolor (255,255,255,255), 1, "default-bold", "center", "center")--Time text 
  
end 
addEventHandler("onClientRender", getRootElement(), mainDrawing) 
  
-- dx draw 
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" 
  if alignX then 
    if alignX == "center" then 
      ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 
    elseif alignX == "right" then 
      ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
    end 
  end 
  if alignY then 
    if alignY == "center" then 
      ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 
    elseif alignY == "bottom" then 
      ay = by - dxGetFontHeight(scale, font) 
    end 
  end 
  local alpha = string.format("%08X", color):sub(1,2) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(getColorFromString("#"..col..alpha)) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) 
  end 
end 
  
  

Link to comment
Check wiki there is a bool value just for this....

"postGUI: A bool representing whether the text should be drawn on top of or behind any ingame GUI (rendered by CEGUI)."

It says "any ingame GUI (rendered by CEGUI).", and as such it will only make it so that DX Drawings are rendered on top of other GUI Elements.

The way DX Drawings work in MTA is based on the order, for example;

  
local draw = 0 
  
function drawThis() 
    dxDrawText("This is a test", 478, 384, 555, 402, tocolor(255, 0, 0, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) 
    dxDrawRectangle(465, 370, 98, 43, tocolor(127, 127, 127, 255), true) -- If I draw this Rectangle AFTER I drew the Text, the text will be UNDER the rectangle. 
end 
  
function testDXDraw() 
    if(draw == 0) then 
        addEventHandler("onClientRender", getRootElement(), drawThis) 
        draw = 1 
    elseif(draw == 1) then 
        removeEventHandler("onClientRender", getRootElement(), drawThis) 
        draw = 0 
    end 
end 
addCommandHandler("testdraw", testDXDraw, false) 
  

Try adding this to your script and move dxDrawText and dxDrawRectangle around and you'll see how it behaves. :)

Link to comment
Hey i have text and image but text is under image how i fix it ?

Part of text

dxDrawText(cashCL, x-750, 735, x-100, y, tocolor(102,135,255,200), 1.5, "default-bold", "left", "top")   
  

Part of image

dxDrawImageSection (325, screenHeight - 37, 64, 32, 131, 37, 64, 32, imgFile) --bg 
  

Where will problem who know ?

I have problem with this others is not significantly.

First scirpt i update

local x,y = guiGetScreenSize() 
  
local showAnim1 = 0 
local showAnim2 = 0 
  
local alpha1 = 200 
local alpha2 = 200      
  
local size1 = 0.75 
local size2 = 0.75    
  
local yup1 = 0      
local yup2 = 0    
  
local p = 0 
local c = 0 
  
function destroyAnim1() 
   showAnim1 = 0 
   size1 = 0.75 
   alpha1 = 200 
   yup1 = 0   
end 
function destroyAnim2() 
   showAnim2 = 0 
   size2 = 0.75 
   alpha2 = 200 
   yup2 = 0   
end 
  
addEventHandler("onClientPreRender", getRootElement(), function()  
  
   local pointsCL = 0 
   local cashCL = 0 
   local HPCL = 0 
  
   if (getElementData(getLocalPlayer(),"Points") ~= false) then 
      pointsCL = getElementData(getLocalPlayer(),"Points") 
   end 
   if (getElementData(getLocalPlayer(),"Cash") ~= false) then 
      cashCL = getElementData(getLocalPlayer(),"Cash") 
   end 
   if (getPedOccupiedVehicle(getLocalPlayer()) ~= false) then 
      HPCL = math.round ( getElementHealth ( getPedOccupiedVehicle(getLocalPlayer()) ), 0) 
   else 
      HPCPL = 0 
   end 
  
   if (p ~= pointsCL) then 
      showAnim1 = 1 
      p = pointsCL 
   end 
  
   if (c ~= cashCL) then 
      showAnim2 = 1 
      c = cashCL 
   end 
----------------------------------------------------------- 
   dxDrawText(pointsCL, x-290, 95, x-60, y, tocolor(245,184,0,200), 0.75, "default-bold", "left", "top" ) 
----------------------------------------------------------- 
------------------------------------------------------------- 
 --  dxDrawText(cashCL, x-740, 735, x-100, y, tocolor(102,135,255,200), 1.5, "default-bold", "left", "top" false, false, true, false, false)   
------------------------------------------------------------- 
--x290,115,x-60,y               0.75 velkost pisma 
--doprava,dole,asinic, 
  
dxDrawText (cashCL, 158, screenHeight - 37, 188, screenHeight - 5, tocolor (255,255,255,255), 1, "default-bold", "right", "center") 
   if (showAnim1 == 1) then           
        dxDrawText(pointsCL, x-290, 95-yup1, x-60, y, tocolor(245,184,0,alpha1), size1, "bankgothic", "right", "top")            
      size1 = size1 + 0.04 
      yup1 = yup1 + 0.75 
      if (alpha1 > 3) then  
         alpha1 = alpha2 - 2  
      else 
         destroyAnim1() 
      end        
   end  
   if (showAnim2 == 1) then              
        dxDrawText(cashCL, x-290, 115-yup2, x-60, y, tocolor(102,140,255,alpha2), size2, "bankgothic", "right", "top")         
      size2 = size2 + 0.04  
      yup2 = yup2 - 0  
      if (alpha2 > 3) then  
         alpha2 = alpha2 - 2  
      else 
         destroyAnim2() 
      end      
   end 
    
           
end 
)  
  
  

and this is second script no link to first script this script create only background

local screenWidth,screenHeight = guiGetScreenSize() 
local owlsFont = dxCreateFont( "files/fonts/font.ttf", 24 ) 
local spriteFile = "files/images/img.png" 
function mainDrawing () 
    local ping = getPlayerPing(getLocalPlayer()) 
    local alivePlayers = getAlivePlayers() 
--Backgrounds 
    dxDrawImageSection (screenWidth - 125, screenHeight - (screenHeight - 10), 128, 64, 1, 287, 128, 64, spriteFile) 
  
dxDrawImageSection (261, screenHeight - 37, 64, 32, 195, 37, 64, 32, spriteFile)--Cash bg -- HERE when i write to fasle i dont see image 
-- vyska,roztiahnutie,natiahnutie, hmmm,horedole, 
  
    dxDrawImageSection (325, screenHeight - 37, 64, 32, 131, 37, 64, 32, spriteFile)--Points bg 
 -- Text time 
    dxDrawText (getServerTime()[2], screenWidth - 42, screenHeight - (screenHeight - 33), screenWidth - 12, screenHeight - (screenHeight - 67), tocolor (255,255,255,255), 1, "default-bold", "center", "center")--Time text 
  
end 
addEventHandler("onClientRender", getRootElement(), mainDrawing) 
  
-- dx draw 
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" 
  if alignX then 
    if alignX == "center" then 
      ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 
    elseif alignX == "right" then 
      ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
    end 
  end 
  if alignY then 
    if alignY == "center" then 
      ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 
    elseif alignY == "bottom" then 
      ay = by - dxGetFontHeight(scale, font) 
    end 
  end 
  local alpha = string.format("%08X", color):sub(1,2) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(getColorFromString("#"..col..alpha)) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) 
  end 
end 
  
  

Link to comment

But you didn't change the priority....

This is the second script with the background:

local screenWidth,screenHeight = guiGetScreenSize() 
local owlsFont = dxCreateFont( "files/fonts/font.ttf", 24 ) 
local spriteFile = "files/images/img.png" 
function mainDrawing () 
    local ping = getPlayerPing(getLocalPlayer()) 
    local alivePlayers = getAlivePlayers() 
--Backgrounds 
    dxDrawImageSection (screenWidth - 125, screenHeight - (screenHeight - 10), 128, 64, 1, 287, 128, 64, spriteFile) 
  
dxDrawImageSection (261, screenHeight - 37, 64, 32, 195, 37, 64, 32, spriteFile)--Cash bg -- HERE when i write to fasle i dont see image 
-- vyska,roztiahnutie,natiahnutie, hmmm,horedole, 
  
    dxDrawImageSection (325, screenHeight - 37, 64, 32, 131, 37, 64, 32, spriteFile)--Points bg 
 -- Text time 
    dxDrawText (getServerTime()[2], screenWidth - 42, screenHeight - (screenHeight - 33), screenWidth - 12, screenHeight - (screenHeight - 67), tocolor (255,255,255,255), 1, "default-bold", "center", "center")--Time text 
  
end 
addEventHandler("onClientRender", getRootElement(), mainDrawing, "true", "high") 
  
-- dx draw 
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) 
  bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" 
  if alignX then 
    if alignX == "center" then 
      ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 
    elseif alignX == "right" then 
      ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font) 
    end 
  end 
  if alignY then 
    if alignY == "center" then 
      ay = ay + (by - ay - dxGetFontHeight(scale, font))/2 
    elseif alignY == "bottom" then 
      ay = by - dxGetFontHeight(scale, font) 
    end 
  end 
  local alpha = string.format("%08X", color):sub(1,2) 
  local pat = "(.-)#(%x%x%x%x%x%x)" 
  local s, e, cap, col = str:find(pat, 1) 
  local last = 1 
  while s do 
    if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end 
    if s ~= 1 or cap ~= "" then 
      local w = dxGetTextWidth(cap, scale, font) 
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) 
      ax = ax + w 
      color = tocolor(getColorFromString("#"..col..alpha)) 
    end 
    last = e + 1 
    s, e, cap, col = str:find(pat, last) 
  end 
  if last <= #str then 
    cap = str:sub(last) 
    dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font) 
  end 
end 
  
  

I changed the priority to high, this way it should be triggered before the one with the text. Try it.

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