From 2546e76da216e9b1ce288b70ebf0985343702782 Mon Sep 17 00:00:00 2001 From: Marc Flerackers Date: Sat, 31 Aug 2024 12:45:53 +0900 Subject: [PATCH] Makes onFixedUpdate attach to fixedUpdate --- examples/fixedUpdate.js | 17 +++++++++++++++++ src/game/events/events.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 examples/fixedUpdate.js diff --git a/examples/fixedUpdate.js b/examples/fixedUpdate.js new file mode 100644 index 00000000..7a2201c4 --- /dev/null +++ b/examples/fixedUpdate.js @@ -0,0 +1,17 @@ +kaplay(); + +let fixedCount = 0; +let count = 0; + +onFixedUpdate(() => { + fixedCount++; +}); + +onUpdate(() => { + count++; + debug.log( + `${fixedDt()} ${Math.floor(fixedCount / time())} ${dt()} ${ + Math.floor(count / time()) + }`, + ); +}); diff --git a/src/game/events/events.ts b/src/game/events/events.ts index 181025bf..22c8f092 100644 --- a/src/game/events/events.ts +++ b/src/game/events/events.ts @@ -28,7 +28,7 @@ export function on( export const onFixedUpdate = overload2( (action: () => void): KEventController => { - const obj = game.root.add([{ update: action }]); + const obj = game.root.add([{ fixedUpdate: action }]); return { get paused() { return obj.paused;