Skip to content

Commit

Permalink
Scroll speed based on delta time for when FPS is low
Browse files Browse the repository at this point in the history
  • Loading branch information
SnowpMakes committed Mar 8, 2024
1 parent 1d938da commit 64a7fe2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
let curUI;
let startUI;
let endUI;
let dt = 1;


function registerBook(ctx, bookFileName){
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -341,7 +343,7 @@

function managePiping(ctx) {
if (lastPipeSpawn > 0){
lastPipeSpawn -= SCROLLSPEED;
lastPipeSpawn -= SCROLLSPEED * dt;
} else {
// Spawn new pipe
lastPipeSpawn = pipeSpawnDelay;
Expand Down

0 comments on commit 64a7fe2

Please sign in to comment.