#Add Screen Transform animations to LSTween!

4 messages · Page 1 of 1 (latest)

sacred spire
#

đź’ˇ Just a suggestion: I'm using LStween animations in my projects instead of the stantard Tween, since the standard Tween consoles a bunch of messages saying that api is going to stop working. But one thing I'm missing on this LSTween is that, aparently, we are not able to make screenTransform animations.

tropic lake
#

Is LSTween script based ? Looking for an easy solution dfferent that tween component aswell

sacred spire
#

Yes, totally script based

sacred spire
#

import { LSTween } from "LSTween.lspkg/LSTween";
import Tween from "LSTween.lspkg/TweenJS/Tween";

export function tweenScrenTransform(screenTransform: ScreenTransform, duration: number = 1000, to:Rect): Tween {
let from = screenTransform.anchors;
return LSTween.rawTween(duration).onUpdate((_, elapsed)=>{
let lerpedRect = lerpRect(from, to, elapsed);
screenTransform.anchors = lerpedRect;
})
}

function lerpRect(rect1:Rect, rect2:Rect, t:number): Rect {
return Rect.create(
lerp(rect1.left, rect2.left, t),
lerp(rect1.right, rect2.right, t),
lerp(rect1.bottom, rect2.bottom, t),
lerp(rect1.top, rect2.top, t)
);
}

function lerp(start:number, end:number, t:number) {
return start + (end - start) * t;
}