From 44ac09a920c7e9353cc4d0d45d6f514c8910bf29 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Thu, 1 Feb 2024 09:18:46 -0500 Subject: [PATCH] Use requestAnimationFrame timestamp for less noise in deltaTime --- src/core/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/main.js b/src/core/main.js index f8e2739204..f5f50e24fc 100644 --- a/src/core/main.js +++ b/src/core/main.js @@ -391,8 +391,8 @@ class p5 { this.callRegisteredHooksFor('afterSetup'); }; - this._draw = () => { - const now = window.performance.now(); + this._draw = requestAnimationFrameTimestamp => { + const now = requestAnimationFrameTimestamp || window.performance.now(); const time_since_last = now - this._lastTargetFrameTime; const target_time_between_frames = 1000 / this._targetFrameRate;