mirror of
https://github.com/kevinveenbirkenbach/roulette-wheel.git
synced 2024-11-24 03:01:04 +01:00
rotation time fix
This commit is contained in:
parent
bab8abb1c2
commit
1ab05d1292
4
app.css
4
app.css
@ -128,6 +128,10 @@ ul {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.menu{
|
||||
width: 23.5rem;
|
||||
}
|
||||
|
||||
.roulette-wheel {
|
||||
position: relative;
|
||||
top: 0;
|
||||
|
12
src/app.ts
12
src/app.ts
@ -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!);
|
||||
|
Loading…
Reference in New Issue
Block a user