Page 1 of 1

[Request] A fading effect timer thing

Posted: Sun Mar 22, 2020 1:15 pm
by isaacjosue
I'm not the best at explaining things so bear with me.
I want it to fade in for a set amount of time when event A happens and fade out when event B happens.
Example:
Timer is set to 30 seconds
If event A happens and I wait 15 seconds then the effect would be at 50% opacity (half faded in).
If event B happens then it would take 15 seconds for the effect to fully fade out.

yes i'm aware this description sucks i'm doing my best please help me

Re: [Request] A fading effect timer thing

Posted: Sun Mar 22, 2020 5:27 pm
by Chanceux2
This year i'm planning to learn how to code

I want to code these types
Codes: show
Lunalua (For SMBX 2.0)
Roblox Lua (For Roblox)
HTMI (For SMBX 2.0)
VRscript (For 38A)
C++ (for SMBX TheXtech)
Long story short: I can't help

Re: [Request] A fading effect timer thing

Posted: Sun Mar 22, 2020 5:42 pm
by Chipss
Chanceux2 wrote:
Sun Mar 22, 2020 5:27 pm
This year i'm planning to learn how to code

I want to code these types
Codes: show
Lunalua (For SMBX 2.0)
Roblox Lua (For Roblox)
HTMI (For SMBX 2.0)
VRscript (For 38A)
C++ (for SMBX TheXtech)
Long story short: I can't help
You shouldn't reply if you're not going to contribute anything to the original topic.

Re: [Request] A fading effect timer thing

Posted: Sun Mar 22, 2020 6:16 pm
by Emral
A "fade" is simply a variable that changes over time and represents an opacity between 0 and 1. For example:
Graphics.drawImage(sprite, x, y, opacity)
https://wohlsoft.ru/pgewiki/LunaLua_glo ... _functions

Can't give more concrete info because the post is fairly vague.

Re: [Request] A fading effect timer thing

Posted: Sun Mar 22, 2020 8:46 pm
by isaacjosue
Enjl wrote:
Sun Mar 22, 2020 6:16 pm
A "fade" is simply a variable that changes over time and represents an opacity between 0 and 1. For example:
Graphics.drawImage(sprite, x, y, opacity)
https://wohlsoft.ru/pgewiki/LunaLua_glo ... _functions

Can't give more concrete info because the post is fairly vague.
Ok scratch the events thing and the fading out I'll figure those out.
I'm looking for a way to do a smooth and continuous fade effect in a set amount of seconds so that when x% percent of the time set has passed the opacity will be at x%.
If timer is set to 10 seconds and I wait 5, then the effect would be at 50% opacity.

My main problem is timing. I am simply unable to make the fading smooth and getting the timing right at the same time.

Re: [Request] A fading effect timer thing

Posted: Mon Mar 23, 2020 1:46 am
by Emral
isaacjosue wrote:
Sun Mar 22, 2020 8:46 pm
Enjl wrote:
Sun Mar 22, 2020 6:16 pm
A "fade" is simply a variable that changes over time and represents an opacity between 0 and 1. For example:
Graphics.drawImage(sprite, x, y, opacity)
https://wohlsoft.ru/pgewiki/LunaLua_glo ... _functions

Can't give more concrete info because the post is fairly vague.
Ok scratch the events thing and the fading out I'll figure those out.
I'm looking for a way to do a smooth and continuous fade effect in a set amount of seconds so that when x% percent of the time set has passed the opacity will be at x%.
If timer is set to 10 seconds and I wait 5, then the effect would be at 50% opacity.

My main problem is timing. I am simply unable to make the fading smooth and getting the timing right at the same time.
Interpolate a variable in onTick by 1/durationInFrames
1 second is roughly 64 frames.
So for 10 seconds:
opacity = opacity + 1/(64*10)

Turn the 10 into a variable and add a multiplier to interpolate backwards (subtract) and then you have a variable that moves between 0 and 1. Of course, ensuring that the variable never leaves the 0-1 range would be good, too, but that is easily done.