Crosshair Posted January 15, 2013 Share Posted January 15, 2013 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
DiSaMe Posted January 15, 2013 Share Posted January 15, 2013 Because you use dxDrawRectangle from the function which is called by the timer, not from the one which is attached to onClientRender. Link to comment
Crosshair Posted January 15, 2013 Author Share Posted January 15, 2013 i figured this, but i dont` have an idea how to make this work. Any idea ? Link to comment
GTX Posted January 15, 2013 Share Posted January 15, 2013 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
Crosshair Posted January 15, 2013 Author Share Posted January 15, 2013 Thx mate. Works great. Link to comment
50p Posted January 15, 2013 Share Posted January 15, 2013 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
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