Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Вопрос How to make alpha fade effect

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
19 Окт 2017
Сообщения
21
Реакции
4
I am looking to add a fade-out effect to my bullet tracers that are drawn with debug overlay, I was wondering how I could make the alpha decrease to 0 after (n) time. For example, I am looking for a way to make alpha go from 255.f to 0.f over 3 seconds linearly. I have tried lots of different functions and have not been able to make one work. Any help would be appreciated.
 
every tick:
alpha - = speed_freq * frametime

What do you mean every tick? Doesn't it already get the frametime and that is always changing?
i mean you need make it every tick(in endscene, or your render function). Frametime you need from globalvars, or deltatime from imgui. But for deltatime i think, you need another formule(i don't know it)
 
Doesn't it already get the frametime and that is always changing
You have an inital value 255.0f and it should be 0.0f in the end, so delta between is 255.0f;
Next you can calculate rate at which animation will go, rate = delta / time, in your case it will be 255 / 3 = 85, so every second animation will decrease by 85.
Every frame you decreasing alpha by rate * frametime, frametime is just a time spent for previous frame in seconds (for example for 60fps it will be 0.01666), so whatever fps is you will get proper animation (even with lags) because of compensation of multiplier.
Last thing you should do is to check that value ain't passed minimal value (0.0f), if it did then animation finished and you should stop decreasing (and probably rendering).
 
Назад
Сверху Снизу