-
Auto-aligning anchor point with “sourceRectAtTime()” aligns point incorrectly
I have a preset with text layers animated with expressions because I’m going to use it alot and I don’t want to manually set each keyframe when text is changed.
Because of this, I have 4 keyframes, two for IN and two for OUT. The text is under a shape layer that acts as a MATE.
Obvsiusly, I have to set the anchor point for the text layer, wich is set at the middle of the left side of the layer using “sourceRectatTime()”. When doing this in a normal layer without animations driven by expressions, it works correctly. When I do it in this text layer, it doesn’t work properly. The anchor point is set slightly over the middle and it offsets al the layer, unaligning all the design.
I attached one screencap to show the issue and make it more graphical.
The code I use for the text layer is the following one (first example slides text from top to bottom, second example slides from left and goes backwards):
And a download link for sample I made, wich has the same issue: https://drive.google.com/file/d/1iY8ik97dJst-aFUEaaMsiENi4zwWjUjR/view?usp=sharing
// customBezier(time, startTime, endTime, startValue, endingValue, beizerPoints); function customBezier(t,tMin,tMax,value1,value2,bezierPoints){ if(arguments.length!==6)return value; var a=value2-value1; var b=tMax-tMin; var c=clamp((t-tMin)/b,0,1); if(!(bezierPoints instanceof Array)||bezierPoints.length!==4)bezierPoints=[0,0,1,1]; return a*h(c,bezierPoints)+value1; function h(f,g){var x=3*g[0]; var j=3*(g[2]-g[0])-x;var k=1-x-j; var l=3*g[1];var m=3*(g[3]-g[1])-l; var n=1-l-m;var d=f;for(var i=0;i<5;i++){var z=d*(x+d*(j+d*k))-f; if(Math.abs(z)<1e-3)break;d-=z/(x+d*(2*j+3*k*d)); } return d*(l+d*(m+d*n)); } } var w = thisLayer.sourceRectAtTime(time, false); if(time<key(2).time) { customBezier(time, key(1).time, key(2).time, [w.left, w.height*1.20], [w.left, w.top/2], [.39,.01,.4,.99]); } else { customBezier(time, key(3).time, key(4).time, [w.left, w.top/2], [w.left, -w.height*2], [.39,.01,.4,.99]); }// customBezier(time, startTime, endTime, startValue, endingValue, beizerPoints); function customBezier(t,tMin,tMax,value1,value2,bezierPoints){ if(arguments.length!==6)return value; var a=value2-value1; var b=tMax-tMin; var c=clamp((t-tMin)/b,0,1); if(!(bezierPoints instanceof Array)||bezierPoints.length!==4)bezierPoints=[0,0,1,1]; return a*h(c,bezierPoints)+value1; function h(f,g){var x=3*g[0]; var j=3*(g[2]-g[0])-x;var k=1-x-j; var l=3*g[1];var m=3*(g[3]-g[1])-l; var n=1-l-m;var d=f;for(var i=0;i<5;i++){var z=d*(x+d*(j+d*k))-f; if(Math.abs(z)<1e-3)break;d-=z/(x+d*(2*j+3*k*d)); } return d*(l+d*(m+d*n)); } } var w = thisLayer.sourceRectAtTime(time, false); if(time<key(2).time) { customBezier(time, key(1).time, key(2).time, [w.width, w.top/2], [0, w.top/2], [.39,.01,.4,.99]); } else { customBezier(time, key(3).time, key(4).time, [0, w.top/2], [w.width, w.top/2], [.39,.01,.4,.99]); }