xTravax Posted July 25, 2014 Share Posted July 25, 2014 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) ? Link to comment
WASSIm. Posted July 25, 2014 Share Posted July 25, 2014 you can use: interpolateBetween Link to comment
xTravax Posted July 25, 2014 Author Share Posted July 25, 2014 i tried reading the wiki about it but i dont understand how to do this with: vector? any example please? Link to comment
Karuzo Posted July 25, 2014 Share Posted July 25, 2014 You can just simply use a variable to define the alpha and do alpha = alpha +/- 1 Link to comment
xTravax Posted July 25, 2014 Author Share Posted July 25, 2014 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 ) Link to comment
50p Posted July 25, 2014 Share Posted July 25, 2014 Don't make the variable local inside the function because the function is called every frame and every time it's called you assign 255 to the same variable. That is logical and alpha will be 255 every frame. Link to comment
xTravax Posted July 25, 2014 Author Share Posted July 25, 2014 text still gets drawn before i even use the command, and alpha doesnt change at all Link to comment
Saml1er Posted July 25, 2014 Share Posted July 25, 2014 You can create a nice fadeIn and FadeOut effect using getTickCount Link to comment
cheez3d Posted July 25, 2014 Share Posted July 25, 2014 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. 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