• Smooth Progress Bar
    6 replies, posted
So I'm making a progress bar for an mp3 player. Since its progress updates every second (I think), it's a little choppy, especially for shorter songs. Here's the code snippet: [code]draw.RoundedBox(2,self:GetWide()/6,dy/2-5,self:GetWide()*2/3,20,color_black) draw.RoundedBox(0,self:GetWide()/6,dy/2-5,(cursong:getposition()/cursong:getlength())*self:GetWide()*2/3,20,Color(100,230,100))[/code] How can I make progress smoothly?
[lua] _Smooth = 0 function GM:HUDPaint( ) if ( cursong:getlength( ) > _Smooth ) then _Smooth = _Smooth + 0.1 elseif ( cursong:getlength( ) < _Smooth ) then _Smooth = _Smooth - 0.1 end draw.RoundedBox(0,self:GetWide()/6,dy/2-5,(cursong:getposition()/_Smooth)*self:GetWide()*2/3,20,Color(100,230,100)) end[/lua]
_Smooth = math.Approach( _Smooth or 0, cursong:getlength( ), 10 * FrameTime( ) ) _Smooth will transition from any point to cursong:getlength( ) in one tenth of a second. By not using FrameTime( ), you move at HUDPaint speed ( and can overshoot the target, which leads to a flickering effect as it tries to auto correct ).
[code] if ( cursong:getposition() > _Smooth ) then _Smooth = math.Approach( _Smooth or 0, cursong:getposition( ), 10 * FrameTime( ) ) elseif ( cursong:getposition() < _Smooth ) then _Smooth = math.Approach( _Smooth or 0, cursong:getposition( ), 10 * FrameTime( ) ) end draw.RoundedBox(0,self:GetWide()/6,dy/2-5,(_Smooth/cursong:getlength())*self:GetWide()*2/3,20,Color(100,230,100))[/code] That's the only one that performed functionally in the sense that it actually progressed, but it didn't make it smoother. Blockier if anything. One thing that I don't understand though is that if I print getposition in the HUDPaint hook, it updates more quickly than once a second. It updates roughly every 0.015 seconds.
HUDPaint is called every frame isn't it? That's why it's updating every 0.015 seconds.
Well what I'm saying is the bar only moves about once every second.
[QUOTE=Kogitsune;17093430]_Smooth = math.Approach( _Smooth or 0, cursong:getlength( ), 10 * FrameTime( ) ) _Smooth will transition from any point to cursong:getlength( ) in one tenth of a second. By not using FrameTime( ), you move at HUDPaint speed ( and can overshoot the target, which leads to a flickering effect as it tries to auto correct ).[/QUOTE] Either way works...
Sorry, you need to Log In to post a reply to this thread.