Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll speed based on delta time for when FPS is low #1

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading