-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Different simulation speed on higher refresh rate monitors #971
Comments
@BeckettOBrien can you provide full code or at least part with renderer? |
Yeah that looks like it should work, could you share a minimal working example? |
I recorded an example on the matter-tools demo and I added a breakpoint before starting the runner and set demo.mov |
Ah I see - what you need to do is make sure you set the correct delta e.g. You'll likely need to detect the frame rate of the browser though for it to be portable, or a better solution is to implement frame skipping and limit it to e.g. 60fps fixed.
|
I started messing around and found that if I comment out the delta limiting ( |
You could also try //put in the main animation loop, returns an array with [FPS, delta, lastCalledTime]
function getCurrentFPS(lastCalledTime) {
if(!lastCalledTime) {
lastCalledTime = Date.now();
fps = 0;
return [fps, 0, lastCalledTime];
}
delta = (Date.now() - lastCalledTime)/1000;
lastCalledTime = Date.now();
return [1/delta, delta, lastCalledTime];
} and you could use it like this: var {Engine} = Matter;
var engine = Engine.Create();
var lastCalledTime;
var fps = 0;
var delta = 0;
function getCurrentFPS(lastCalledTime) {
if(!lastCalledTime) {
lastCalledTime = Date.now();
fps = 0;
return [fps, 0, lastCalledTime];
}
delta = (Date.now() - lastCalledTime)/1000;
lastCalledTime = Date.now();
return [1/delta, delta, lastCalledTime];
}
function MainLoop() {
// Get "getCurrentFPS"'s Output
GCFPSOutput = getCurrentFPS(lastCalledTime);
// Set fps, delta, and lastCalledTime
FPS = GCFPSOutput[0];
delta = GCFPSOutput[1];
lastCalledTime = GCFPSOutput[2];
// Updates engine with delta
Engine.Update(engine, delta*1000);
} |
Hey, the solutions above didn't work for me. |
sorry, I commented on this so long ago, that I forgot how it works :p |
Closing this thread to refer to updates in #702 on this topic, thanks again for the reports here. |
Hi! I've been playing around with matter-js and noticed that when I switched from my laptop to a high-refresh rate display, the speed of objects falling under gravity increased dramatically. When I change the monitor settings down to 60 Hz, the object falls normally. I tried using this when creating my runner:
but the simulation looks the same. Is there anything I'm missing? Thanks!
The text was updated successfully, but these errors were encountered: