Skip to main content
Inspiring
January 16, 2023
Answered

Scroll variable text lenghts

  • January 16, 2023
  • 2 replies
  • 948 views

Hey Pros!

 

I'm searching for an expression that scrolls a text sideways based on its length.

Let's say you have these two texts: «Sample» and «This is a longer sample».

The composition has a defined width that allows the shorter text «Sample» do be displayed in full length but the longer one will be cutted off somewhere in the middle of «…longer…».

 

My idea is to have the text scroll by from the start to its end, based on the length of the text. So, the beginning of the scentence will be shown and starts scrolling sideways until it reaches its end.

What I found are various ways to do this with a fixed length to scroll (100px to the right, …). But because I need to do this for a lot of texts it would be great to have an expression on the text layer, rewrite the text and render out the new one without manually change the scrolling position each time.

 

When having a shorter text like «Sample», the text can just stay where it is without moving.

 

Does someone have an idea how I could get this done?

Thanks in advance!

This topic has been closed for replies.
Correct answer Gabriel Signer

Hi @Mylenium 
That one works but it moves the text to the wrong side. (I attached an mp4)

 

I think the expression is close to final 😉 Thanks again!

 


Ah! Solved!

 

I changed the minus to a plus here: {X=linear(time,tStart,tEnd,wPos[0],wPos[0]+wDiff)} and added a «-20»  here: wDiff=wCom-wTex-20;

 

That's because not every text gets perfectly aligned to the left side of the comp. I now placed it a little in the comp, so every letter is fully displayed and the comp gets moved a little more (20px) than the comp width.

 

Here's the final expression:

 

tStart=0; //start time

tEnd=5; //end time

wPos=thisLayer.transform.position;

wTex=thisLayer.sourceRectAtTime().width;

wCom=thisComp.width;

wDiff=wCom-wTex-20;

 

if(wDiff < 0)

{X=linear(time,tStart,tEnd,wPos[0],wPos[0]+wDiff)}

else {X=wPos[0]};

 

Y=wPos[1];

 

[X,Y]


Thanks guys for your help! I really appretiate it!

2 replies

Community Expert
January 17, 2023

Here is a simpler expression with a little better speed control.

w = sourceRectAtTime().width/2;
cw = thisComp.width;
t = time - inPoint;
s = 3;//speed multiplier
value1 = thisComp.width + w;
if (w * 2 < cw){
	value2 = w + 100;
}
else{
	value2 = cw - w - 100
}
x = easeOut(t / s, value1, value2);
y = value[1];
[x, y]

Give that one a try.

Mylenium
Legend
January 16, 2023

A simple sourceRectAtTime() and calculating the differences will do.

 

tStart=0; //start time
tEnd=5; //end time

wPos=thisLayer.transform.position;
wTex=thisLayer.sourceRectAtTime().width;
wCom=thisComp.width;
wDiff=wCom-wTex;

if(wDiff >0)
{X=linear(time,tStart,tEnd,wPos[0],wPos[0]-wDiff}
else
{X=wPos[0]};

Y=wPos[1];

[X,Y]

 

This is the basic drill. It assumes left-aligned text. You may also need to account for padding and of course will need to tweak the values to your needs.

 

Mylenium

Inspiring
January 16, 2023

Hi Mylenium!

 

Thanks for the fast response!
When adding the expression to the position it moves every text thats shorter than the comp width. However, it should move the text if it sticks out of the comp on the right side. Is there a simple fix for that?

Thanks again!

 

Community Expert
January 16, 2023

If you want the text to scroll off the left side of the screen when the line is longer than the comp width, you'll need to calculate the width of the text layer, set up an if/else statement that gives you two ending values for an easeOut ineterpolation.

 

Try something like this for center-justified text.

 

 

w = sourceRectAtTime().width/2;
cw = thisComp.width;
t = time - inPoint;
tMin = 0;
tMax = w / cw * 5;// sets the speed
value1 = thisComp.width + w;
if (w * 2 < cw){
	value2 = w + 100;
}
else{
	value2 = cw - w - 100
}
x = easeOut(t, tMin, tMax, value1, value2);
y = value[1];
[x, y]