Yep, another coding issue: UTIL_ScreenFade Created 3 years ago2021-06-12 01:30:10 UTC by Alexis_of_Steel Alexis_of_Steel

Created 3 years ago2021-06-12 01:30:10 UTC by Alexis_of_Steel Alexis_of_Steel

Posted 3 years ago2021-06-12 01:30:10 UTC Post #345693
Hello! I was wondering how to make UTIL_ScreenFade last longer than 16 seconds (by default, that is the maximum duration of this UTIL).
I mean, is it possible to edit the code of UTIL_ScreenFade so that the duration of the screen fade effect lasts longer than 16 seconds?
In my case, I want it to last 30 seconds, no more:
UTIL_ScreenFade( pPlayer, Vector(255,0,0), 1, 30, 128, FFADE_IN ); // float fadeHold only lasts 16 s
I have searched for a tutorial and didn't really find anything. :(
Thanks in advance.
Posted 3 years ago2021-06-12 09:37:37 UTC Post #345694
You can modify the UTIL_ScreenFadeBuild function to make this work:
void UTIL_ScreenFadeBuild( ScreenFade &fade, const Vector &color, float fadeTime, float fadeHold, int alpha, int flags )
{
    fade.duration = FixedUnsigned16( fadeTime, 1<<8 );        // 8.8 fixed
    fade.holdTime = FixedUnsigned16( fadeHold, 1<<8 );        // 8.8 fixed
    fade.r = (int)color.x;
    fade.g = (int)color.y;
    fade.b = (int)color.z;
    fade.a = alpha;
    fade.fadeFlags = flags | FFADE_LONGFADE;
}
Located here: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/util.cpp#L726-L735

The FFADE_LONGFADE flag indicates that a longer fade time can be used. The parameter to FixUnsigned16 has to be modified for both calls to use 1 << 8.
Posted 3 years ago2021-06-12 13:29:36 UTC Post #345696
Oh, God. It worked! Thanks a lot, Solokiller!
You must be logged in to post a response.