Skip to main content
brandonb96942845
Inspiring
September 4, 2022
Question

AE Expression for "Previous Frame"?

  • September 4, 2022
  • 2 replies
  • 1129 views

Hi all,

 

Got a quick one today: is there an AE script term that tells it "previous frame"? Literally all I'm trying to do is compare Y position values between the current frame and the previous one. I've come up with a way to do it, but I want to know if there's a better/proper way to go about it. Here's my solution:

temp1 = 1 //number of frames to count backward;
temp2 = framesToTime(temp1, fps=1.0/thisComp.frameDuration)
transform.yPosition.valueAtTime(time - temp2)

The way I did it is a tad clumsy, but what I basically did was to calculate the duration of one frame relative to the frame rate of the comp, and then subtract that amount from the current time.

It feels like this is more elaborate than it needs to be, but this is the best way I could think of (or find while Googling) to do what I was trying to do.

(If you're wondering what this is doing it's going into a scroll bar setup I've developed that will light up an "up" arrow if the previous frame's Y value is more than the current one, and a "down" arrow if it's more; a variant is going to light up the scroll bar itself.)

This topic has been closed for replies.

2 replies

Community Expert
September 4, 2022

If the layer you are looking at is one layer above the layer that follows this will do what you want to do.

 

p = thisComp.layer(index - 1).position;
d = thisComp.frameDuration * 1; // 1 = number of frames to delay
npY = p.valueAtTime(time - d);
[p[0], npY[1]]

 

 

Misread your post. This for opacity would work:

p = thisComp.layer(index - 1).position;
npY = p.valueAtTime(time - thisComp.frameDuration);
if (p[1] < npY[1])
	100;
else
	0;

You could add a linear expression to fade the layer in and out over a few frames.

Dan Ebberts
Community Expert
Community Expert
September 4, 2022

I think I'd try something like this:

transform.yPosition.speed < 0 ? 100 : 0