Jump to content

[Issue]dxDrawRectangle into a progress bar


Crosshair

Recommended Posts

I`m trying to make a progress bar with dxdraw. All works well but the rectangle flickers every time till the timer stops. I need help on that so the rectangle would not flicker anymore.

local screenW, screenH = guiGetScreenSize() 
function render() 
    if (isTimer(timer) == false) then 
        i=0 
        timer = setTimer(function() 
            dxDrawRectangle((screenW - 23) / 2-131, (screenH - 10) / 2, i, 10, tocolor(144, 3, 3, 255), true) 
            i=i+1 
        end, 50, 100) 
    end 
    removeEventHandler("onClientRender", root, render) 
end 
addEventHandler("onClientRender", root, render) 

Link to comment

Try this:

  
local screenW, screenH = guiGetScreenSize() 
local i = 0 
function render() 
    dxDrawRectangle((screenW - 23) / 2-131, (screenH - 10) / 2, i, 10, tocolor(144, 3, 3, 255), true) 
    i=i+1 
    if i >= 100 then 
        removeEventHandler("onClientRender", root, render) 
    end 
end 
addEventHandler("onClientRender", root, render) 
  

Link to comment

If you still want it to work by a timer you can draw the rectangle with a width that is updated by a timer.

function startProgress() -- call this function when you want to show the progress 
    i=0; 
    setTimer( function() i=i+1 end, 50, 100); -- update the width with a timer (you can change the interval to higher value to make it update longer) 
    addEventHandler( "onClientRender", root, render );  
end 
  
function render( ) 
    dxDrawRectangle((screenW - 23) / 2-131, (screenH - 10) / 2, i, 10, tocolor(144, 3, 3, 255), true) 
    if i >= 100 then 
        removeEventHandler( "onClientRender", root, render ); 
    end 
end 

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