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

Physics run way to fast on a really good gaming PC #1152

Closed
lafkpages opened this issue Aug 21, 2022 · 8 comments
Closed

Physics run way to fast on a really good gaming PC #1152

lafkpages opened this issue Aug 21, 2022 · 8 comments

Comments

@lafkpages
Copy link

I showed my cousin a game I made with Matter.js but his computer is so good the game runs like 3 to 4 times faster than it should and is impossible to play.

Is there a way to set an FPS limit?

@ggorlen
Copy link

ggorlen commented Aug 21, 2022

Are you using your own runner or the built-in MJS runner? A minimal example would be useful.

@lafkpages
Copy link
Author

Built-in runner.

This is how the runner is made.

// create runner
let runner = Runner.create({
  isFixed: false // I tried both true and false, same result
});

// run the engine
Runner.run(runner, engine);

The full script is here (didn't post all because it's 2.3k lines of code)
The game is here

@ProgrammingLife
Copy link

So what to do with 144Hz?
If we have 30fps then we need to add one more extra step. Ok. But what to do with 144fps?

@LexSerest
Copy link

LexSerest commented Apr 17, 2023

Fix fps / fix fast simulation

Events.on(runner, 'tick',() => {
  runner.deltaMin = runner.fps > 60 ? 1000 / runner.fps : 1000 / 60;
})

I have been solving this problem for a long time.

how to catch a bug

chrome increases fps when you lose focus from the active tab

an example with the use of an official demo

focus:
image

unfocus:
image

@liabru please add a fix to the runner code

@MinhChanh6
Copy link

MinhChanh6 commented Jul 25, 2023

Hi everyone, I try with the code of @LexSerest above but it doesn't work?!.

Has anyone found a way yet?

Here my example code:
code

@catinrage
Copy link

@MinhChanh6 you missed the this before first runner at line 7, maybe that will fix.

@liabru
Copy link
Owner

liabru commented Nov 12, 2023

Closing this thread to refer to updates in #702 on this topic, thanks again for the reports here.

@liabru
Copy link
Owner

liabru commented Jun 24, 2024

As of 0.20.0 there is now built in Matter.Runner support by default for fixed timestep with high refresh displays see #1300.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants