Jump to content

dxDrawText alpha animation


xTravax

Recommended Posts

Posted

hello!

i wanted to ask something

how can i make some dx text dissapear after 6 seconds with animation of fading out(alpha decreasing-fourth argument i believe) ?

Posted

i am really sorry i am a total noob in this,i tried to make it but it just draws the text and doesnt decrease alpha at all because my code is wrong,feel free to laugh

screenWidth,screenHeight = guiGetScreenSize() 
function someFunction() 
local alpha = 255 
if (alpha) then 
dxDrawText ( "TEST", screenWidth/2, screenHeight/2, screenWidth, screenHeight, tocolor ( 255, 255, 255, alpha ), 1, "bankgothic" ) 
alpha = alpha - 1 
end 
end 
addCommandHandler("dx",someFunction) 
  
  
function HandleTheRendering ( ) 
    addEventHandler ( "onClientRender", root, someFunction ) -- keep the text visible with onClientRender. 
end 
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering ) 

Posted
  
local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); 
local StartTick,Duration,EndTick = nil,5000,nil; 
local Debounce = false; 
local function RenderHandler() 
    local CurrentTick = getTickCount(); -- get the current tick; 
    local Progress = (CurrentTick-StartTick)/Duration; -- calculate the progress between 0 and 1 using simple math; 
    local Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad"); 
    dxDrawText("This text is fading in...",ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"bankgothic"); 
    if CurrentTick>=EndTick then -- if the animation is finished; 
        StartTick,EndTick = nil,nil; -- clear variables; 
        removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler; 
        Debounce = false; -- we can now use /dx again; 
    end; 
end; 
addCommandHandler("dx",function() 
    if not Debounce then -- if the text isn't already rendering; 
        Debounce = true; 
        StartTick = getTickCount(); -- get the current tick as the start tick of the animation; 
        EndTick = StartTick+Duration; -- calculate the end tick; 
        addEventHandler("onClientRender",root,RenderHandler); -- add the render handler only when you type the command; 
    end; 
end); 
  

I have not tested it, but it should work.

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