From 75098adbdbe1a83b077f52967bc4168de1becfc7 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 7 Mar 2024 13:17:40 +0100 Subject: [PATCH] allow offsetting onFrame --- packages/canvas/draw.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/canvas/draw.mjs b/packages/canvas/draw.mjs index 20bf7fd6..2ea531cf 100644 --- a/packages/canvas/draw.mjs +++ b/packages/canvas/draw.mjs @@ -64,7 +64,7 @@ Pattern.prototype.draw = function (callback, { from, to, onQuery } = {}) { // this is a more generic helper to get a rendering callback for the currently active haps // TODO: this misses events that are prolonged with clip or duration (would need state) -Pattern.prototype.onFrame = function (fn) { +Pattern.prototype.onFrame = function (fn, offset = 0) { if (typeof window === 'undefined') { return this; } @@ -72,7 +72,7 @@ Pattern.prototype.onFrame = function (fn) { cancelAnimationFrame(window.strudelAnimation); } const animate = () => { - const t = getTime(); + const t = getTime() + offset; const haps = this.queryArc(t, t); fn(haps, t, this); window.strudelAnimation = requestAnimationFrame(animate);