Spielerando

Timing and easing

Learning paths through this topic

Let a held button buy again and again, faster the longer it is held

Tapping an upgrade fifty times is tiring, but holding the button can buy way too fast or, on a slow frame, skip purchases. A good hold starts with a pause, then speeds up in steps. Here is how to compute how many purchases belong to each frame so that the result is the same on every phone.

Show the progress of a generator that finishes many times per second

Early in an idle game a generator takes ten seconds and its bar fills nicely. Later it finishes ten times a second, and the bar flickers madly or counts wrongly. Here is how to count finished rounds correctly, including an unexpected rounding trap, and when to stop drawing a bar and show a rate.

Make a money counter run smoothly when the game only updates once a second

If the number on screen changes only when the game does its once-a-second sums, it stutters. Guessing ahead between those sums fixes the look but invites two bugs: the guess running beyond what will really arrive, and the number dropping when the true value is a little lower. Here is a way that avoids both, while still dropping instantly on a purchase.

Pay a double-speed boost correctly when it runs out while the player is away

A ten-minute boost is easy while the game is open. The trouble starts when the player leaves after four minutes and returns an hour later: giving the boost for the whole hour is too generous, giving none is unfair. Here is the exact split, plus the guard against clocks that go backwards.

Count up the earnings from the time away without taking forever for huge sums

When a player returns to an idle game, counting up what they earned feels great, until the sum is a trillion and the count takes a minute, or it is 40 and the count is over before it begins. The length of the count should follow how impressive the sum is, not the sum itself. Here is the rule and its end point.

Stop one long lag spike from throwing everything across the screen

When the window loses focus or the computer stalls for a moment, the next frame reports a huge time step and characters teleport, tweens jump to the end and physics explodes. Here is how to tell a one-off spike from a genuinely slow computer and treat each properly.

Keep things moving on the beat when the music and the picture drift apart

A pulsing light or a rhythm lane that follows the game timer slowly slides away from the song, and reading the song position directly looks choppy because it updates in jumps. Here is how to get a steady beat clock and judge button presses against it fairly.

Animate a value through several keyframes, each stretch with its own feel

A logo that swings in, waits, and drops out needs more than one start and end value. Here is how to sample any moment of such a track, what to return before the first and after the last point, and how to hold a value for a while or make a sudden jump.

Make a kill-streak meter drain faster the higher you climb, exactly

A score multiplier that drains faster at higher levels keeps experts busy, but if the speed changes in the middle of a long frame the meter gets the wrong number, and slow computers hold on to levels longer than fast ones. Here is the exact way to drain across level borders.

Push a hit enemy back exactly 100 pixels on any frame rate

Knockback made with a speed that shrinks each frame throws enemies a different distance on every computer, and a second hit during the push can launch them across the level. Here is a push whose length you choose and that stays the same everywhere.

Pull the hero up a ledge along a path that never cuts through the corner

When the hero grabs a ledge and the climb animation plays, moving straight from hand to top cuts diagonally through the corner, and a long frame can end up inside the wall. Here is a two-part path with an exact finish that you can time to the animation.

Let list items appear one after another without taking forever

A staggered entrance looks great with five items and ridiculous with fifty, because the last one arrives seconds late. Here is how to keep the cascade feel while keeping the whole thing inside a time you choose, and how to play it backwards when closing.