Private
Public Access
1
0

fix Handy FPS Problems
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m51s

This commit is contained in:
Sebastian Unterschütz
2025-11-25 18:50:05 +01:00
parent 5175f52652
commit 553f4c2944
3 changed files with 39 additions and 7 deletions

View File

@@ -44,14 +44,39 @@ function gameOver(reason) {
drawGame();
}
function gameLoop() {
if (!isLoaded) return;
if (isGameRunning && !isGameOver) {
updateGameLogic(); currentTick++; score++;
const scoreEl = document.getElementById('score'); if (scoreEl) scoreEl.innerText = Math.floor(score / 10);
if (currentTick - lastSentTick >= CHUNK_SIZE) sendChunk();
function gameLoop(timestamp) {
requestAnimationFrame(gameLoop);
if (!isLoaded || !isGameRunning || isGameOver) {
lastTime = timestamp;
return;
}
drawGame(); requestAnimationFrame(gameLoop);
if (!lastTime) lastTime = timestamp;
const deltaTime = timestamp - lastTime;
lastTime = timestamp;
if (deltaTime > 1000) {
accumulator = 0;
return;
}
accumulator += deltaTime;
while (accumulator >= MS_PER_TICK) {
updateGameLogic();
currentTick++;
score++;
if (currentTick - lastSentTick >= CHUNK_SIZE) sendChunk();
accumulator -= MS_PER_TICK;
}
const scoreEl = document.getElementById('score');
if (scoreEl) scoreEl.innerText = Math.floor(score / 10);
drawGame();
}
async function initGame() {