9 Replies Latest reply on Feb 11, 2012 6:22 AM by Lars Renklint

# Fade out on every keyframe

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.

• ###### 1. Re: Fade out on every keyframe

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

hold =.01;;

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

100

}else{

}

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

• ###### 2. Re: Fade out on every keyframe

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);

hold =.01;;

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

100

}else{

}

else {value}

}

• ###### 3. Re: Fade out on every keyframe

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

• ###### 4. Re: Fade out on every keyframe

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%...

• ###### 5. Re: Fade out on every keyframe

Try this:

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;

}else

100

Dan

• ###### 6. Re: Fade out on every keyframe

Thank you Dan, that was much more accurat then the solution I found. My code actually worked quite well in a simple test, but in a more complex test there were a lot of flickering. Your code works perfect for all but the very first keyframe.

http://screencast.com/t/rPZbB5ljjZbl

Please have a look at this short video and notice the flickering in the beginning. Any thoughts?

• ###### 7. Re: Fade out on every keyframe

Hmmm... it's hard to figure out what's going on. Can you post a screenshot of your keyframes?

Dan

• ###### 8. Re: Fade out on every keyframe

In my test comp were the keyframes were in the layers position property everything worked perfect.

In this comp the green solids opacity is controlled by a slider in the midi layer. The green solids position also has an expression that uses the midi-slider.

• ###### 9. Re: Fade out on every keyframe

Thanks for the suggestion to post a screendump. That made me see the extra keyframe that I didn't notice before. With that deleted everything works perfect.