rotation time fix

This commit is contained in:
p-wojt 2022-01-10 22:40:07 +01:00
parent bab8abb1c2
commit 1ab05d1292
2 changed files with 10 additions and 6 deletions

View File

@ -128,6 +128,10 @@ ul {
margin: auto;
}
.menu{
width: 23.5rem;
}
.roulette-wheel {
position: relative;
top: 0;

View File

@ -268,21 +268,21 @@ function startRoulette() {
360 * ROTATIONS +
(items.length - 1 - guessItemIndex) * segmentAngle +
Math.random() * segmentAngle;
console.log(maxAngle);
endTime = (maxAngle / rotate_by) * (1000 / ANIMATION_FPS);
console.log(endTime);
beginAnimateRoulette();
}
}
}
let totalTime = 0;
function beginAnimateRoulette() {
//TODO: animations doesn't work as expected (endTime too low or totalTime incrementing faster than expected)
if (totalTime < endTime) {
drawRouletteWheel(easeOut(totalTime, 0, maxAngle, endTime));
const angle = easeOut(totalTime, 0, maxAngle, endTime);
if (totalTime < endTime || maxAngle - angle > 0.1) {
setTimeout(() => {
animationId = window.requestAnimationFrame(beginAnimateRoulette);
drawRouletteWheel(angle);
totalTime += 1000 / ANIMATION_FPS;
animationId = window.requestAnimationFrame(beginAnimateRoulette);
}, 1000 / ANIMATION_FPS);
} else {
window.cancelAnimationFrame(animationId!);