fix Handy FPS Problems
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m51s
All checks were successful
Dynamic Branch Deploy / build-and-deploy (push) Successful in 1m51s
This commit is contained in:
@@ -6,6 +6,9 @@ const JUMP_POWER = -12;
|
|||||||
const GROUND_Y = 350;
|
const GROUND_Y = 350;
|
||||||
const GAME_SPEED = 5;
|
const GAME_SPEED = 5;
|
||||||
const CHUNK_SIZE = 60;
|
const CHUNK_SIZE = 60;
|
||||||
|
const TARGET_FPS = 60;
|
||||||
|
const MS_PER_TICK = 1000 / TARGET_FPS;
|
||||||
|
|
||||||
|
|
||||||
// RNG Klasse
|
// RNG Klasse
|
||||||
class PseudoRNG {
|
class PseudoRNG {
|
||||||
|
|||||||
@@ -44,14 +44,39 @@ function gameOver(reason) {
|
|||||||
drawGame();
|
drawGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameLoop() {
|
function gameLoop(timestamp) {
|
||||||
if (!isLoaded) return;
|
requestAnimationFrame(gameLoop);
|
||||||
if (isGameRunning && !isGameOver) {
|
|
||||||
updateGameLogic(); currentTick++; score++;
|
if (!isLoaded || !isGameRunning || isGameOver) {
|
||||||
const scoreEl = document.getElementById('score'); if (scoreEl) scoreEl.innerText = Math.floor(score / 10);
|
lastTime = timestamp;
|
||||||
if (currentTick - lastSentTick >= CHUNK_SIZE) sendChunk();
|
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() {
|
async function initGame() {
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ let lastSentTick = 0;
|
|||||||
let inputLog = [];
|
let inputLog = [];
|
||||||
let isCrouching = false;
|
let isCrouching = false;
|
||||||
|
|
||||||
|
// Tick Time
|
||||||
|
let lastTime = 0;
|
||||||
|
let accumulator = 0;
|
||||||
|
|
||||||
// Grafiken
|
// Grafiken
|
||||||
let sprites = {};
|
let sprites = {};
|
||||||
let playerSprite = new Image();
|
let playerSprite = new Image();
|
||||||
|
|||||||
Reference in New Issue
Block a user