[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CS1BC83CWVFCV8DX5V2BRA":3,"skill-same:01M7CS1BC83CWVFCV8DX5V2BRA":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CS1BC83CWVFCV8DX5V2BRA","game-loop-and-time",null,"Use when writing anything that moves, animates, counts down or simulates - per-frame vs fixed-step callbacks per engine, the accumulator loop with interpolation, delta-scaled smoothing, pause and time scale, and determinism.","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Fgame-loop-and-time\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: game-loop-and-time\ncategory: gameplay\ndescription: Use when writing anything that moves, animates, counts down or simulates - per-frame vs fixed-step callbacks per engine, the accumulator loop with interpolation, delta-scaled smoothing, pause and time scale, and determinism.\ntech_stack: Game core\nsource: informed by Glenn Fiedler's Gaffer on Games articles (Fix Your Timestep) and the engines' own docs; own wording\n---\n# Game Loop and Time\n\n## Overview\n\nTwo clocks run in every game: the render frame (variable, as fast as the machine allows) and the simulation step (fixed, so physics and rules behave the same everywhere). Most \"it moves faster on my machine\", tunnelling, jitter and desync bugs come from putting work on the wrong clock or forgetting to scale by the right delta.\n\n**Core principle:** Simulate on a fixed step, render with interpolation, and scale every time-based value by the delta of the clock it runs on.\n\n## Where each clock lives\n\n| Engine | Per frame (variable) | Fixed step | Default fixed rate |\n|---|---|---|---|\n| Unity | `Update`, `LateUpdate` — `Time.deltaTime` | `FixedUpdate` — `Time.fixedDeltaTime` | 0.02 s (50 Hz) |\n| Godot | `_process(delta)` | `_physics_process(delta)` | 60 ticks\u002Fs (`physics\u002Fcommon\u002Fphysics_ticks_per_second`) |\n| Unreal | `Tick(DeltaSeconds)` | physics substepping \u002F async physics tick | project physics settings |\n| Bevy | `Update` — `Res\u003CTime>` | `FixedUpdate` — `Res\u003CTime>` is `Time\u003CFixed>` there | 64 Hz |\n| Phaser | `update(time, delta)` (ms) | Arcade physics' own step (`fps`, `fixedStep`) | 60 |\n| PixiJS 8 | `ticker.add(t => …)` — `t.deltaMS` | your accumulator | — |\n| three.js \u002F Babylon.js | `setAnimationLoop` + `THREE.Timer` \u002F `engine.getDeltaTime()` (ms) | your accumulator, or the physics plugin's | — |\n| MonoGame | `Update(GameTime)` | `IsFixedTimeStep = true` (default) | 1\u002F60 s |\n| pygame | `dt = clock.tick(60) \u002F 1000` | your accumulator | — |\n\nUse the engine's fixed callback for physics and authoritative rules. Write your own loop only where the engine has none (web renderers, pygame, custom servers).\n\n## The accumulator loop (web, pygame, servers)\n\n```ts\nconst STEP = 1 \u002F 60;\nconst MAX_FRAME = 0.25;           \u002F\u002F clamp: a 3 s tab-switch must not run 180 steps\nlet acc = 0;\nlet last = performance.now();\n\nfunction frame(now: number) {\n  const frameTime = Math.min((now - last) \u002F 1000, MAX_FRAME);\n  last = now;\n  acc += frameTime;\n  while (acc >= STEP) {\n    previous.copyFrom(current);   \u002F\u002F keep the last state for interpolation\n    simulate(current, STEP);      \u002F\u002F rules + physics, fixed dt only\n    acc -= STEP;\n  }\n  render(interpolate(previous, current, acc \u002F STEP));\n  requestAnimationFrame(frame);\n}\nrequestAnimationFrame(frame);\n```\n\n- Clamp the frame time, or one long frame triggers the \"spiral of death\" (more steps → longer frame → more steps).\n- Render the blend of the last two simulation states; without it, a 60 Hz simulation on a 144 Hz display stutters.\n- Engines with a fixed callback offer interpolation too: Unity `Rigidbody.interpolation = Interpolate`, Godot `physics\u002Fcommon\u002Fphysics_interpolation` (2D since 4.3, 3D since 4.4), Bevy interpolation crates or a manual `Time\u003CFixed>::overstep_fraction()` blend.\n\n## Scale by delta — including smoothing\n\n```csharp\n\u002F\u002F ❌ frame-rate dependent: twice as fast at 120 FPS, crawls at 30\ntransform.position += velocity;\ncamera.position = Vector3.Lerp(camera.position, target, 0.1f);\n\n\u002F\u002F ✅ delta-scaled; exponential smoothing that reads the same at any frame rate\ntransform.position += velocity * Time.deltaTime;\nfloat t = 1f - Mathf.Exp(-sharpness * Time.deltaTime);\ncamera.position = Vector3.Lerp(camera.position, target, t);\n```\n\n```gdscript\n# ❌ counts frames: a 1 s cooldown is 0.42 s at 144 FPS\nvar frames_left := 60\nfunc _process(_delta: float) -> void:\n    frames_left -= 1\n\n# ✅ counts seconds\nvar cooldown_left := 1.0\nfunc _process(delta: float) -> void:\n    cooldown_left = maxf(0.0, cooldown_left - delta)\n```\n\nAcceleration needs care too: `velocity += accel * dt; position += velocity * dt` (semi-implicit Euler) is stable at a fixed step and drifts at a variable one — another reason to simulate on the fixed clock.\n\n## Pause, slow motion and UI time\n\n- Time scale slows the game, not the menus: Unity `Time.timeScale` with UI on `Time.unscaledDeltaTime`; Godot `Engine.time_scale` with pause menus on `process_mode = PROCESS_MODE_ALWAYS`; Bevy `Time\u003CVirtual>` (pausable, scalable) vs `Time\u003CReal>`; Unreal `SetGlobalTimeDilation` with UI ticking while paused.\n- `timeScale = 0` stops `FixedUpdate` in Unity — anything that must run while paused (menus, input polling for \"unpause\") cannot live there.\n- Pause on focus loss (`visibilitychange` on the web, `OnApplicationPause`, `NOTIFICATION_APPLICATION_FOCUS_OUT`), and clamp the first delta after resuming.\n\n## Determinism, when the design needs it\n\nReplays, lockstep RTS and rollback netcode need the same inputs to produce the same state on every machine:\n\n- Fixed step only; no variable `dt` reaches the simulation.\n- One seeded RNG owned by the simulation; cosmetic effects use a separate generator so they cannot shift the sequence.\n- No iteration over hash maps or sets whose order is unspecified (use sorted keys, `IndexMap`, or arrays); no wall-clock reads inside a step.\n- Floating point differs across compilers, CPUs and WASM vs native — use fixed-point math or keep all peers on one build and platform.\n- Test it: same seed + same input log → same state hash after N steps.\n\n## Testing time-based code\n\n```ts\nit(\"covers the same distance at 30 and 60 steps per second\", () => {\n  const a = new Mover({ speed: 5 }); for (let i = 0; i \u003C 60; i++) a.step(1 \u002F 60);\n  const b = new Mover({ speed: 5 }); for (let i = 0; i \u003C 30; i++) b.step(1 \u002F 30);\n  expect(a.x).toBeCloseTo(5, 5);\n  expect(b.x).toBeCloseTo(a.x, 5);\n});\n```\n\nInject `dt`; never sleep in a test. Engine tests advance frames explicitly (`yield return new WaitForFixedUpdate()`, `runner.simulate_frames(n)`, `app.update()` with a manual time strategy).\n\n## Common Mistakes\n\n- Moving a rigidbody by writing its transform in `Update`\u002F`_process` — it fights the physics step and tunnels.\n- Reading input in `FixedUpdate`: a key pressed between two steps is missed. Read in the frame callback, consume in the fixed one.\n- Delta in milliseconds treated as seconds (Phaser, PixiJS `deltaMS`, Babylon `getDeltaTime()`).\n- PixiJS `ticker.deltaTime` is a frame-scaled factor (≈1 at 60 FPS), not seconds.\n- A constant lerp factor for camera smoothing.\n\n## Red Flags\n\n- `frameCount`, `% 60` or a frame counter used as a timer.\n- `Time.time` \u002F `performance.now()` inside a rule class.\n- A physics fix done by raising the frame cap or relying on vsync.\n","# Game Loop and Time\n\n## Overview\n\nTwo clocks run in every game: the render frame (variable, as fast as the machine allows) and the simulation step (fixed, so physics and rules behave the same everywhere). Most \"it moves faster on my machine\", tunnelling, jitter and desync bugs come from putting work on the wrong clock or forgetting to scale by the right delta.\n\n**Core principle:** Simulate on a fixed step, render with interpolation, and scale every time-based value by the delta of the clock it runs on.\n\n## Where each clock lives\n\n| Engine | Per frame (variable) | Fixed step | Default fixed rate |\n|---|---|---|---|\n| Unity | `Update`, `LateUpdate` — `Time.deltaTime` | `FixedUpdate` — `Time.fixedDeltaTime` | 0.02 s (50 Hz) |\n| Godot | `_process(delta)` | `_physics_process(delta)` | 60 ticks\u002Fs (`physics\u002Fcommon\u002Fphysics_ticks_per_second`) |\n| Unreal | `Tick(DeltaSeconds)` | physics substepping \u002F async physics tick | project physics settings |\n| Bevy | `Update` — `Res\u003CTime>` | `FixedUpdate` — `Res\u003CTime>` is `Time\u003CFixed>` there | 64 Hz |\n| Phaser | `update(time, delta)` (ms) | Arcade physics' own step (`fps`, `fixedStep`) | 60 |\n| PixiJS 8 | `ticker.add(t => …)` — `t.deltaMS` | your accumulator | — |\n| three.js \u002F Babylon.js | `setAnimationLoop` + `THREE.Timer` \u002F `engine.getDeltaTime()` (ms) | your accumulator, or the physics plugin's | — |\n| MonoGame | `Update(GameTime)` | `IsFixedTimeStep = true` (default) | 1\u002F60 s |\n| pygame | `dt = clock.tick(60) \u002F 1000` | your accumulator | — |\n\nUse the engine's fixed callback for physics and authoritative rules. Write your own loop only where the engine has none (web renderers, pygame, custom servers).\n\n## The accumulator loop (web, pygame, servers)\n\n```ts\nconst STEP = 1 \u002F 60;\nconst MAX_FRAME = 0.25;           \u002F\u002F clamp: a 3 s tab-switch must not run 180 steps\nlet acc = 0;\nlet last = performance.now();\n\nfunction frame(now: number) {\n  const frameTime = Math.min((now - last) \u002F 1000, MAX_FRAME);\n  last = now;\n  acc += frameTime;\n  while (acc >= STEP) {\n    previous.copyFrom(current);   \u002F\u002F keep the last state for interpolation\n    simulate(current, STEP);      \u002F\u002F rules + physics, fixed dt only\n    acc -= STEP;\n  }\n  render(interpolate(previous, current, acc \u002F STEP));\n  requestAnimationFrame(frame);\n}\nrequestAnimationFrame(frame);\n```\n\n- Clamp the frame time, or one long frame triggers the \"spiral of death\" (more steps → longer frame → more steps).\n- Render the blend of the last two simulation states; without it, a 60 Hz simulation on a 144 Hz display stutters.\n- Engines with a fixed callback offer interpolation too: Unity `Rigidbody.interpolation = Interpolate`, Godot `physics\u002Fcommon\u002Fphysics_interpolation` (2D since 4.3, 3D since 4.4), Bevy interpolation crates or a manual `Time\u003CFixed>::overstep_fraction()` blend.\n\n## Scale by delta — including smoothing\n\n```csharp\n\u002F\u002F ❌ frame-rate dependent: twice as fast at 120 FPS, crawls at 30\ntransform.position += velocity;\ncamera.position = Vector3.Lerp(camera.position, target, 0.1f);\n\n\u002F\u002F ✅ delta-scaled; exponential smoothing that reads the same at any frame rate\ntransform.position += velocity * Time.deltaTime;\nfloat t = 1f - Mathf.Exp(-sharpness * Time.deltaTime);\ncamera.position = Vector3.Lerp(camera.position, target, t);\n```\n\n```gdscript\n# ❌ counts frames: a 1 s cooldown is 0.42 s at 144 FPS\nvar frames_left := 60\nfunc _process(_delta: float) -> void:\n    frames_left -= 1\n\n# ✅ counts seconds\nvar cooldown_left := 1.0\nfunc _process(delta: float) -> void:\n    cooldown_left = maxf(0.0, cooldown_left - delta)\n```\n\nAcceleration needs care too: `velocity += accel * dt; position += velocity * dt` (semi-implicit Euler) is stable at a fixed step and drifts at a variable one — another reason to simulate on the fixed clock.\n\n## Pause, slow motion and UI time\n\n- Time scale slows the game, not the menus: Unity `Time.timeScale` with UI on `Time.unscaledDeltaTime`; Godot `Engine.time_scale` with pause menus on `process_mode = PROCESS_MODE_ALWAYS`; Bevy `Time\u003CVirtual>` (pausable, scalable) vs `Time\u003CReal>`; Unreal `SetGlobalTimeDilation` with UI ticking while paused.\n- `timeScale = 0` stops `FixedUpdate` in Unity — anything that must run while paused (menus, input polling for \"unpause\") cannot live there.\n- Pause on focus loss (`visibilitychange` on the web, `OnApplicationPause`, `NOTIFICATION_APPLICATION_FOCUS_OUT`), and clamp the first delta after resuming.\n\n## Determinism, when the design needs it\n\nReplays, lockstep RTS and rollback netcode need the same inputs to produce the same state on every machine:\n\n- Fixed step only; no variable `dt` reaches the simulation.\n- One seeded RNG owned by the simulation; cosmetic effects use a separate generator so they cannot shift the sequence.\n- No iteration over hash maps or sets whose order is unspecified (use sorted keys, `IndexMap`, or arrays); no wall-clock reads inside a step.\n- Floating point differs across compilers, CPUs and WASM vs native — use fixed-point math or keep all peers on one build and platform.\n- Test it: same seed + same input log → same state hash after N steps.\n\n## Testing time-based code\n\n```ts\nit(\"covers the same distance at 30 and 60 steps per second\", () => {\n  const a = new Mover({ speed: 5 }); for (let i = 0; i \u003C 60; i++) a.step(1 \u002F 60);\n  const b = new Mover({ speed: 5 }); for (let i = 0; i \u003C 30; i++) b.step(1 \u002F 30);\n  expect(a.x).toBeCloseTo(5, 5);\n  expect(b.x).toBeCloseTo(a.x, 5);\n});\n```\n\nInject `dt`; never sleep in a test. Engine tests advance frames explicitly (`yield return new WaitForFixedUpdate()`, `runner.simulate_frames(n)`, `app.update()` with a manual time strategy).\n\n## Common Mistakes\n\n- Moving a rigidbody by writing its transform in `Update`\u002F`_process` — it fights the physics step and tunnels.\n- Reading input in `FixedUpdate`: a key pressed between two steps is missed. Read in the frame callback, consume in the fixed one.\n- Delta in milliseconds treated as seconds (Phaser, PixiJS `deltaMS`, Babylon `getDeltaTime()`).\n- PixiJS `ticker.deltaTime` is a frame-scaled factor (≈1 at 60 FPS), not seconds.\n- A constant lerp factor for camera smoothing.\n\n## Red Flags\n\n- `frameCount`, `% 60` or a frame counter used as a timer.\n- `Time.time` \u002F `performance.now()` inside a rule class.\n- A physics fix done by raising the frame cap or relying on vsync.\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"informed by Glenn Fiedler's Gaffer on Games articles (Fix Your Timestep) and the engines' own docs; own wording","gameplay","Game core","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Fgame-loop-and-time",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill game-loop-and-time",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill game-loop-and-time",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill game-loop-and-time","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Fgame-loop-and-time\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]