fix game
This commit is contained in:
@@ -191,9 +191,10 @@ export default function App() {
|
|||||||
// Only start timer on first damage
|
// Only start timer on first damage
|
||||||
if (!scoreTimerRef.current) {
|
if (!scoreTimerRef.current) {
|
||||||
scoreEndRef.current = Date.now() + 20000;
|
scoreEndRef.current = Date.now() + 20000;
|
||||||
|
let lastLeft = -1;
|
||||||
const tick = () => {
|
const tick = () => {
|
||||||
const left = Math.max(0, Math.ceil((scoreEndRef.current - Date.now()) / 1000));
|
const left = Math.max(0, Math.ceil((scoreEndRef.current - Date.now()) / 1000));
|
||||||
setScoreTimeLeft(left);
|
if (left !== lastLeft) { lastLeft = left; setScoreTimeLeft(left); }
|
||||||
if (left > 0) scoreRafRef.current = requestAnimationFrame(tick);
|
if (left > 0) scoreRafRef.current = requestAnimationFrame(tick);
|
||||||
};
|
};
|
||||||
tick();
|
tick();
|
||||||
|
|||||||
Reference in New Issue
Block a user