Jump to content

Alpha Problem


Karuzo

Recommended Posts

Hey guys,

i have a problem with my Alpha in my Scoreboard Script.

I want it to fade it in.

but that doesn't really work.

The problem is it sets the alpha to 0 if it reached 255.

And how can i let it fade back if i unpress tab.

  
local alpha = 0 
  
    function Alpha() 
        if alpha < 255 then  
            alpha = alpha + 10  
        end 
    end 
  
  
--Alpha is triggered if i press tab. 
  
  

Hope you can help me :-)

Link to comment
addEventHandler("onClientRender", root, 
    function () 
        if (alpha >= 255) then 
            alpha = 255 
        end 
    end 
) 

I got same problem when I was doing animation on DX's ;p

If your animation is done, you can remove this event using removeEventHandler.

Link to comment

So like this ?

  
    addEventHandler("onClientRender", root, 
        function () 
            if (alpha >= 255) then 
                alpha = 255 
            elseif (alpha == 0) then 
                 removeEventHandler("onClientRender", root, Alpha) 
            end 
        end 
    ) 
  

Link to comment
  
fadeScoreboard = function(keyState) 
    local fadeProgress = 0 
    if keyState == "down" then 
        fadeProgress = fadeProgress+0.01 
        local alphaValue = interpolateBetween(0,0,0,255,0,0,fadeProgress,"InOutQuad") 
        --dxDrawStuff + tocolor(r,g,b,alphaValue) 
        if alphaValue>=1 then 
            removeEventHandler("onClientRender",root,renderScoreboard) 
        end 
    elseif keyState == "up" then 
        fadeProgress = fadeProgress-0.01 
        local alphaValue = interpolateBetween(0,0,0,255,0,0,fadeProgress,"InOutQuad") 
        --dxDrawStuff + tocolor(r,g,b,alphaValue) 
        if alphaValue<=0 then 
            removeEventHandler("onClientRender",root,renderScoreboard) 
        end 
    end 
end 
addEventHandler("onPlayerJoin",root,function() 
    bindKey(source,"tab","both",function(_,keyState) 
        function renderScoreboard() 
            fadeScoreboard(keyState) 
        end 
        addEventHandler("onClientRender",root,renderScoreboard) 
    end) 
end) 
  

Edited by Guest
Link to comment
     
        function changeAlpha () 
            if (alpha >= 255) then 
                alpha = 255 
                removeEventHandler("onClientRender", root, changeAlpha)                
            end 
        end 
        addEventHandler("onClientRender", root, changeAlpha) 

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