• Drawing a temporary fading red rectangle
    3 replies, posted
I want to draw a red rectangle on the player's screen that slowly fades away completely after 2 seconds, I'm not sure how to do the fading away stuff, with CurTime()? Timers? plz help =S
I suppose you could do something like this (untested) [lua] local time local alpha function DoRectangle() //set time time = (CurTime() + 2) alpha = 255 end function RectanglePaint() //bailout if (alpha == 0) then return end if (CurTime() > time) then //reduce alpha alpha = (alpha - 1) end //draw rect surface.SetDrawColor(255, 0, 0, alpha) surface.DrawRect(0, 0, ScrW(), ScrH()) end hook.Add("HUDPaint", "DoRedRectangle", RectanglePaint) [/lua]
google is your friend [QUOTE=jrj996;30817532] [lua] --init.lua function GM:PlayerInitialSpawn(player) umsg.Start("FadeToStart",player) umsg.End() end --cl_init.lua local intro = false local alpha = 255 usermessage.Hook("FadeToStart",function() intro = true end) timer.Create("EndFade",0.1,0,function() if intro && alpha > 0 then alpha = alpha - 1 end if alpha < 1 then timer.Destroy("EndFade") end end) function FadeEffect() draw.RoundedBoxEx(1,0,0,ScrW(),ScrH(),Color(0,0,0,alpha)) end hook.Add("HUDPaint","FadeEffect",FadeEffect) [/lua] Untested but it should work, hopefully. [/QUOTE]
I googled already...
Sorry, you need to Log In to post a reply to this thread.