Gradually Decreasing Opacity Over Time

Is it possible to have a gradually decreasing opacity, let say minus 20 per second and stop the decrease once 0 is reach.
I will be using this idea to “if music is stopped or paused, it will gradually decrease and set it to 100 opacity if music is playing”.

If you’re using KLWP, you can simply use Animation > Fade Out. You can have that react to a Global Switch that is tied up to $mi(state)$.

1 Like

This turned out to be much harder than I originally thought. I tried various combinations of tu and fl timers with no success, and then switched to try it with animations which also gave me problems with non-intuitive or weird behavior. However eventually I came up with a solution although probably better programmers can simplify or improve.

1/ Create an OVERLAY GROUP at the basic (top) level of your design.
2/ Create or move your image or shape items in the Overlap Group.
3/ In the Group options select Animation and press + to create a rule.
4/ Click on the center of the rule (to the right of ‘Disabled’) and select React On.
5/ Select FORMULA and then in the second line Formula type or paste:
$if(mi(state)=PLAYING,f,b)$
so if music is playing the animation will go forward, and any other option (stopped, paused, etc.) will reverse [1 can replace f, and 0 can replace b]).
6/ Select ACTION: Fade In
7/ Select EASE: Normal
8/ Select DURATION and convert to formula then paste:
$if(mi(state)=PLAYING,1,100)$
which sets the animation speed to immediate (1) and 100 (10 seconds) if not playing.
9/ Select DELAY, convert to formula and paste:
$if(mi(state)=PLAYING,0,10)$
which sets the animation delay when music starts to 0 and when the music stops to 10 (1 second).

Obviously you can change the duration and delay values to whatever you like. And that should do it, I hope. At least it works on my Android 14, Samsung A54 5G, UI One 6.

The formulas are required because I am unable to explain why it seems impossible, at least in my testing of dozens of combinations, to create one fade in animation rule with fixed duration and delay values, and a separate fade out animation rule with different fixed values. Possibly @frank or @Ace or someone better than me can do that.

3 Likes

This topic was automatically closed 25 days after the last reply. New replies are no longer allowed.