feat(common): use delta time for the button selector animation

This commit is contained in:
2026-01-07 11:14:44 +01:00
parent e6dc73fabd
commit 5e3336bbe8

View File

@@ -14,12 +14,12 @@ const { onRender } = useScreen();
const app = useAppStore(); const app = useAppStore();
const { assets } = useAssets(); const { assets } = useAssets();
const ANIMATION_SPEED = 0.25; const ANIMATION_SPEED = 15;
const CORNER_SIZE = 11; const CORNER_SIZE = 11;
let [currentX, currentY, currentWidth, currentHeight] = props.rect; let [currentX, currentY, currentWidth, currentHeight] = props.rect;
onRender((ctx) => { onRender((ctx, deltaTime) => {
const [targetX, targetY, targetWidth, targetHeight] = props.rect; const [targetX, targetY, targetWidth, targetHeight] = props.rect;
const dx = targetX - currentX; const dx = targetX - currentX;
const dy = targetY - currentY; const dy = targetY - currentY;
@@ -34,10 +34,11 @@ onRender((ctx) => {
) { ) {
[currentX, currentY, currentWidth, currentHeight] = props.rect; [currentX, currentY, currentWidth, currentHeight] = props.rect;
} else { } else {
currentX += dx * ANIMATION_SPEED; const speed = (ANIMATION_SPEED * deltaTime) / 1000;
currentY += dy * ANIMATION_SPEED; currentX += dx * speed;
currentWidth += dw * ANIMATION_SPEED; currentY += dy * speed;
currentHeight += dh * ANIMATION_SPEED; currentWidth += dw * speed;
currentHeight += dh * speed;
} }
const x = Math.floor(currentX); const x = Math.floor(currentX);