Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

auto scale text box

New Here ,
Oct 06, 2021 Oct 06, 2021

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

Screen Shot 2021-10-06 at 5.25.40 PM.png

 

how can i fix it?

 
TOPICS
Expressions
144
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2021 Oct 06, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 09, 2021 Oct 09, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2021 Oct 09, 2021
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines