Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alessey committed Mar 5, 2025
1 parent b931893 commit 0d5ed13
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion create-onchain/templates/minikit/app/components/Sammy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { encodeAbiParameters } from "viem";
import ArrowSvg from "../svg/ArrowSvg";
import MiniKitLogo from '../svg/MiniKitLogo';

const FPS = 60;
const MS_PER_FRAME = 1000 / FPS;
const NUM_TARGETS_PER_LEVEL = 10;

const GameState = {
Expand Down Expand Up @@ -338,11 +340,17 @@ function Paused() {
)
}

let msPrev = performance.now();
const useGameLoop = (callback: () => void, dependencies: DependencyList) => {
useEffect(() => {
let frameId: number;
const loop = () => {
callback();
const msNow = performance.now();
const delta = msNow - msPrev;
if (delta > MS_PER_FRAME) {
callback();
msPrev = msNow - (delta % MS_PER_FRAME);
}
frameId = requestAnimationFrame(loop);
};
frameId = requestAnimationFrame(loop);
Expand Down

0 comments on commit 0d5ed13

Please sign in to comment.