diff --git a/src/lib/utils/lifecycle.js b/src/lib/utils/lifecycle.js index f1047be..8284a80 100644 --- a/src/lib/utils/lifecycle.js +++ b/src/lib/utils/lifecycle.js @@ -1,14 +1,16 @@ import { onMount } from 'svelte'; -/** @param {() => void} callback */ +/** @param {(elapsedTime: number, deltaTime: number) => void} callback */ export function onFrame(callback) { onMount(() => { /** @type {number} */ let frame; + let lastTime = 0.0; - requestAnimationFrame(function loop() { + requestAnimationFrame(function loop(frameTime) { frame = requestAnimationFrame(loop); - callback(); // TODO are there useful args we can pass here? + callback(frameTime, frameTime - lastTime); + lastTime = frameTime; }); return () => { diff --git a/src/routes/examples/_content/03-animated-cube/BugBox.svelte b/src/routes/examples/_content/03-animated-cube/BugBox.svelte new file mode 100644 index 0000000..b445394 --- /dev/null +++ b/src/routes/examples/_content/03-animated-cube/BugBox.svelte @@ -0,0 +1,25 @@ + + + + \ No newline at end of file diff --git a/src/routes/examples/_content/03-animated-cube/index.svelte b/src/routes/examples/_content/03-animated-cube/index.svelte new file mode 100644 index 0000000..3b10742 --- /dev/null +++ b/src/routes/examples/_content/03-animated-cube/index.svelte @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + diff --git a/src/routes/examples/_content/03-animated-cube/meta.json b/src/routes/examples/_content/03-animated-cube/meta.json new file mode 100644 index 0000000..99a0033 --- /dev/null +++ b/src/routes/examples/_content/03-animated-cube/meta.json @@ -0,0 +1,3 @@ +{ + "title": "Animated cube" +} diff --git a/static/example-thumbnails/animated-cube.jpg b/static/example-thumbnails/animated-cube.jpg new file mode 100644 index 0000000..6be64a8 Binary files /dev/null and b/static/example-thumbnails/animated-cube.jpg differ