Copy link to clipboard
Copied
Hi, i have this code for a subtitle text box size
var tex=thisComp.layer(index-1);
var w=tex.sourceRectAtTime(time-tex.inPoint,true).width;
s = 10;
if (marker.numKeys > 0){
m = marker.nearestKey(time);
t = m.time;
afterM= t+s*thisComp.frameDuration;
beforeM= t-s*thisComp.frameDuration;
aw = linear(w,0,1820,t,beforeM);
aw1 = linear(w,1820,0,t,afterM);
if (t<time){
ease(time,t,afterM,aw,w)
}else{
ease(time,t,beforeM,w,aw1)
}
}else{
w
}
I want the size of the box becomes the size of the next subtitle text smoothly, but in the above code, the size of the box becomes zero, and then it becomes the size of the text
how can i fix it?
Copy link to clipboard
Copied
You need to run the code in a loop and iterate through the previous and next markers/ text keyframes/ layers, respectively. The code by itself really doesn't do anything but add a smooth transition based on time, but only does so once.
Mylenium
Copy link to clipboard
Copied
I don't really get it, the size of the box is animated according to the markers and there is no problem for looping, my problem is with the animation box, when the text get bigger or smaller, the box gets the same size as the text smoothly, but in that code, the box size becomes 0 and then becomes as size as the text
Copy link to clipboard
Copied
Exactly the point: It zeroes out because there are undefined situations where it can't determine which was the previous marker and which one is the next. It's literally in the function's name: nearestKey() - if time is smaller than the half between the keys the nearest key is the previous one, otherwise it's the next one. That's why it needs to be run in a loop and have extra code to consistently calculate which markers are being used.
Mylenium