From 64a7fe2d80d51b51afd82a9e9155f256bd015b16 Mon Sep 17 00:00:00 2001 From: Snowp Date: Fri, 8 Mar 2024 11:23:36 +0100 Subject: [PATCH] Scroll speed based on delta time for when FPS is low --- src/index.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.html b/src/index.html index 81ac2ff..c8d1a91 100644 --- a/src/index.html +++ b/src/index.html @@ -40,6 +40,7 @@ let curUI; let startUI; let endUI; +let dt = 1; function registerBook(ctx, bookFileName){ @@ -86,11 +87,11 @@ } update(){ - this.x -= SCROLLSPEED; + this.x -= SCROLLSPEED * dt; if (showPipesDebug) this.debugRectangle.x = this.x; // Moves books to the left this.books.forEach(book => { - book.x -= SCROLLSPEED; + book.x -= SCROLLSPEED * dt; }); // Check if pipe is past owl @@ -305,9 +306,10 @@ } } -function update() { +function update(time, delta) { + dt = delta / 16.5; if (!GAMEENDED){ - bg.tilePositionX += SCROLLSPEED; // keep the background moving! + bg.tilePositionX += SCROLLSPEED * dt; // keep the background moving! } if (GAMESTATE === "UI"){ curUI.update(); @@ -341,7 +343,7 @@ function managePiping(ctx) { if (lastPipeSpawn > 0){ - lastPipeSpawn -= SCROLLSPEED; + lastPipeSpawn -= SCROLLSPEED * dt; } else { // Spawn new pipe lastPipeSpawn = pipeSpawnDelay;