Warcraft III resources & community, 2003–2006 · archived

FadeUnitVertexColor

not rated
Submitted by KaTTaNaFunctions0 downloads
Will gradually fade a units vertex color from one color to another.
Very useful for making units fade in and out by fading the alpha.
r,g,b,a values should be between 0 and 1.
0 alpha is transparent.
* Requires the Handle Var functions.

Source

// =======================================
//    Fade unit vertex colors

function FadeUnitVertexColor_Update takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local real r = GetHandleReal(t, "r") + GetHandleReal(t, "dr")
    local real g = GetHandleReal(t, "g") + GetHandleReal(t, "dg")
    local real b = GetHandleReal(t, "b") + GetHandleReal(t, "db")
    local real a = GetHandleReal(t, "a") + GetHandleReal(t, "da")
    local integer step = GetHandleInt(t, "step") - 1
    local unit u = GetHandleUnit(t, "u")
    call SetUnitVertexColor(u, R2I(r*255), R2I(g*255), R2I(b*255), R2I(a*255))
    if ( u == null or step <= 0 ) then
        call FlushHandleLocals(t)
        call DestroyTimer(t)
        return
    endif
    call SetHandleReal(t, "r", r)
    call SetHandleReal(t, "g", g)
    call SetHandleReal(t, "b", b)
    call SetHandleReal(t, "a", a)
    call SetHandleInt(t, "step", step)
endfunction
function FadeUnitVertexColor takes unit u, real r1, real g1, real b1, real a1, real r2, real g2, real b2, real a2, real time returns nothing
    local timer t
    local real update = 0.05
    if ( time <= 0 ) then
        call SetUnitVertexColor(u, R2I(r2*255), R2I(g2*255), R2I(b2*255),  R2I(a2*255))
        return
    endif
    call SetUnitVertexColor(u, R2I(r1*255), R2I(g1*255), R2I(b1*255),  R2I(a1*255))
    set t = CreateTimer()
    call SetHandleReal(t, "r", r1)
    call SetHandleReal(t, "g", g1)
    call SetHandleReal(t, "b", b1)
    call SetHandleReal(t, "a", a1)
    call SetHandleReal(t, "dr", update*(r2-r1)/time)
    call SetHandleReal(t, "dg", update*(g2-g1)/time)
    call SetHandleReal(t, "db", update*(b2-b1)/time)
    call SetHandleReal(t, "da", update*(a2-a1)/time)
    call SetHandleHandle(t, "u", u)
    call SetHandleInt(t, "step", R2I(time/update + 0.99))
    call TimerStart(t, update, true, function FadeUnitVertexColor_Update)
endfunction

Comments

0

No comments.