I built Schrute Farm, an idle beet clicker game inspired by 'The Office', using Phaser 3. While game loops are straightforward, scaling an incremental game introduces interesting challenges: managing huge numbers, tracking progression offline, and keeping game state synchronized across standard web views and the Canvas container.
Uncoupling Logic Ticks from Frame Rates
Phaser's update loop is tied to the browser's requestAnimationFrame, which fluctuates based on system load or background status. Running game calculations directly in this loop causes instability. To prevent this, I separated the logical state loop from the rendering loop. The game logic executes on a fixed-frequency timer (1 tick per second), updates the state properties, and then lets Phaser's visual loop interpolate animations smoothly based on frame rates.
Handling Large Numbers and BigInt Constraints
Incremental games run into mathematical limitations when numbers grow beyond Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). Standard JavaScript floats lose precision, causing rounding errors that break the upgrade economics. To resolve this, I implemented a custom formatting engine that stores numbers as coefficients and exponent powers (e.g. representing a value as 1.54 * 10^24) and translates them into readable short scales like 'Septillion' in the interface.
Analytical Math for Offline Progression
When a player closes the game, running tick-by-tick simulations to catch up upon relaunch is a memory disaster. Instead of iterating through thousands of ticks, I solved this analytically. When the game shuts down, I save the Unix timestamp. On relaunch, the game calculates the elapsed time delta and runs a single mathematical equation to compute the accumulated earnings. This keeps load times instant and protects performance.
Compounding Equations for Upgrade Scales
Balancing clicker economies requires precise cost scaling curves. I structured the upgrade formulas using geometric progression models, where Cost = Base * Rate^Level. By tuning the progression exponent carefully, I prevented rapid game economy inflation while maintaining a satisfying progress loop during long sessions.
- Prestige Multipliers: The analytical equation factors in active prestige multipliers that increase production compounding yields.
- Offline Efficiency Caps: A configurable percentage caps offline efficiency, giving players strategic reasons to check back regularly.
- Resource Distribution: Calculated resources are automatically split between wallet balances and warehouse capacities upon initialization.
Optimizing Phaser Canvas Rendering and Texture sheets
Rendering hundreds of animated sprites simultaneously can choke mobile GPUs. I packed all farm beet sprites and animations into unified texture sheets using atlas JSON configs. This reduced the active WebGL draw calls count by 80%, guaranteeing stable 60fps rendering even on low-end smartphones.
Zustand State Bridge for Multi-Scene Phaser Architectures
To prevent gameplay fatigue, I added separate mini-game modes: Solitaire and a Match-3 puzzle named Beet Blast. These run inside separate Phaser scenes but must interact with the player's core wallet and inventory. I structured a unified Zustand game state bridge. When a player scores in Beet Blast, the scene emits events that update the global Zustand store, which in turn recalculates the core idle economy and unlocks upgrades in the main layout.
“Idle gaming is a simulation database masquerading as an interactive animation canvas.”
“Incremental math is the art of giving players the illusion of infinite growth within the strict limits of computer binary precision.”
Be careful with offline time exploits: players can easily cheat by modifying their local system clocks. I resolved this by validating time deltas against a trusted NTP server during startup.
This architecture ensures that game progression remains highly secure against local time-manipulation cheats, keeping state synchronized across scenes.
Danya Yudin (Sabraman)
Designer & Frontend Engineer
Design-led frontend and product developer specializing in web applications, interface design, and Telegram systems.