Skip to main content
Known Participant
February 10, 2012
Resuelto

Fade out on every keyframe

  • February 10, 2012
  • 1 respuesta
  • 2532 visualizaciones

Another newbie question.

Tried this expression on a layers opacity:

d = Math.abs(time -transform.position.nearestKey(time).time);

easeOut(d, 100, 0)

The idea was to make the layers opacity go from 100% to 0 on every keyframe.

What actually happens is the opacity goes down to 36% in the middle between two keyframes, then goes up to 100 again.

Este tema ha sido cerrado para respuestas.
Mejor respuesta de Dan Ebberts

Then I have to rephrase it...

What I would like is that the layer should start every new keyframe with an opacity of 100%, and fade away to 0 right before it reaches the next keyframe. Which again starts att 100%...


Try this:

fade = 1; // fade duration

n = 0;

p  = transform.position;

if (p.numKeys > 0){

  n = p.nearestKey(time).index;

  if (p.key(n).time <= time) n++;

}

if (n > p.numKeys) n = 0;

if (n > 0){

  t = p.key(n).time;

  ease(time,t-fade,t,100,0);

}else

  100

Dan

1 respuesta

Known Participant
February 10, 2012

Found this: http://library.creativecow.net/articles/ebberts_dan/ae6_exp.php

So if I knew that the keyframes where 1 sec apart this would do the trick

fade = .99;

hold =.01;;

t = time%(fade + hold + fade);

if(t < fade){

  linear(t,0,fade,100,0)

}else if (t < (fade + hold)){

  100

}else{

  linear(t,fade+hold,fade+hold+fade,100,0)

}

Now I just need to figure out the math for calculating the time between keyframes

Known Participant
February 10, 2012

This works good enough, but I would like to find a better solution for the first keyfram.

if(transform.position.numKeys>0);

{

n =transform.position.nearestKey(time).index;

if(n>1){

p = transform.position.key(n-1);

fade = transform.position.key(n).time - p.time;

hold =.01;;

t = time%(fade + hold + fade);

if(t < fade){

  linear(t,0,fade,100,0)

}else if (t < (fade + hold)){

  100

}else{

  linear(t,fade+hold,fade+hold+fade,100,0)}

}

else {value}

}

Dan Ebberts
Community Expert
Community Expert
February 10, 2012

If you want it to fade out at each keyframe, doesn't that mean it will always be at 0% after the first keyframe?

Dan