phaserjs/phaser/time-and-timers
Claude Code and agent skill by phaserjs/phaser
- community
Checking that the SKILL.md file is still in the repository.
Phaser 4 time: the Scene Clock (this.time), delayedCall, addEvent and the TimerEvent config (delay, repeat, loop, startAt, timeScale, paused), Timelines (this.add.timeline with at, in, from, run, tween, set, sound, event), time scale, pausing, delta time in update, and the FPS limit (fps.limit, game.loop.setFPSLimit). Use when spawning enemies every few seconds, making a countdown or a cooldown, delaying an action, scripting a cutscene or intro, adding slow motion, or making movement frame-rate independent. Corrects v3 habits: this.tweens.timeline() is gone (use this.add.timeline), setTimeout and setInterval ignore pause and time scale, a finished TimerEvent can't be re-added without reset, this.time.timeScale doesn't slow tweens or physics. Triggers on: timer, delayedCall, addEvent, TimerEvent, Clock, Timeline, cutscene, countdown, cooldown, spawn every, slow motion, timeScale, delta, FPS limit.
Install
npx vskill@latest install phaserjs/phaser/time-and-timersSKILL.md
The same SKILL.md was published earlier as phaserjs/phaser/time-and-timers.
Time and timers
The Scene Clock (this.time) and its Timer Events, Timelines for scripted sequences, time scale, delta time and the FPS limit.
Source: src/time/Clock.js, src/time/TimerEvent.js, src/time/Timeline.js, src/time/typedefs/, src/core/TimeStep.js (the game loop). Related: tweens, scenes (pausing a Scene), game-setup-and-config (the fps config).
Quick start
this.timeis the Scene's Clock. Its timers run in the Scene's update step, so they stop while the Scene is paused, followthis.time.timeScale, and are destroyed when the Scene shuts down.setTimeoutandsetIntervaldo none of this, so don't use them for game logic.- Use arrow functions. In a
functioncallback with nocallbackScope,thisis the TimerEvent, not the Scene. delayedCall(delay, callback, args, callbackScope)isaddEventwith no repeat.
Timer Events
addEventputs the timer in a pending list. It starts on the next frame.delay: 0withrepeatorloopthrowsTimerEvent infinite loop created via zero delay.timer.delaycan be changed while it runs. The new delay is used from the next fire.- A long frame can fire a short timer more than once in the same frame.
- Read it with
getProgress()(this fire, 0 to 1),getOverallProgress(),getElapsed(),getRemaining(),getRemainingSeconds(),getOverallRemaining()andgetRepeatCount()(repeats left). - Stop it with
timer.remove(), ortimer.remove(true)to fire it one last time.this.time.removeEvent(timer)removes it at once.this.time.removeAllEvents()removes them all. - Pause one with
timer.paused = true, or all of them withthis.time.paused = true.
Reusing a Timer Event
The Clock destroys a timer when it finishes, which clears its callback. To use it again, give reset the full config, then add it:
reset doesn't add it to the Clock. Since 4.3, addEvent logs a warning when given a destroyed timer, and timer.isDestroyed says whether it has been. Making a new timer with addEvent(config) is usually simpler.
Common patterns
Spawn every N seconds, getting faster
Countdown
Or make one delayedCall(30000, ...) and show Math.ceil(timer.getRemainingSeconds()) in update.
Cooldown
time (the same as this.time.now) is the game loop's time. It doesn't follow this.time.timeScale, or stop while the Clock is paused. For a cooldown that slows with slow motion, use a delayedCall that sets a flag.
Timelines
this.add.timeline(events) runs a script of events at set times: callbacks, tweens, property changes, sounds and custom events. Use it for cutscenes, intros, tutorials and attack patterns. v3's this.tweens.timeline() doesn't exist; use a Timeline, or a Tween Chain for tweens only.
| Key | What it does | |
|---|---|---|
at | ms from the start. Default 0. | |
in | ms after the Timeline's current elapsed. For adding events to a running Timeline. | |
from | ms after the previous event in the array. from beats in, which beats at. | |
target | The object for set, and this in the callbacks. | |
set | Properties to set on target. Needs target. | |
tween | A tween config, Tween Chain config or Tween, added to this.tweens. It needs its own targets. | |
sound | A sound key, or { key, config }. | |
event | Emits this event on the Timeline, with target (or the Timeline) as the argument. | |
run | A callback. this is target, or the Timeline. | |
loop | A callback run on each repeat of the Timeline, but not on its first play. | |
if | A callback. Return false to skip the event's actions. It still counts as run. | |
once | Remove the event once it has run, for good. It doesn't come back on reset() or a repeat. | |
stop | Stop the Timeline. This emits COMPLETE. |
An event's actions run in this order: if, set, loop, tween, sound, event, run, stop.
Control:
play()starts from the beginning.pause()andresume()also pause and resume the tweens it started: useresume(), notplay(), to carry on.timeline.stop()stops it without emittingCOMPLETE.reset()stops the tweens its events started, goes back to the start and plays.clear()removes every event.add(config | array)adds events, even while it runs.repeat()orrepeat(-1)repeats forever.repeat(2)plays it 3 times.repeat(false)turns it off. Only-1means forever.isPlaying(),getProgress()(events run, over all events),elapsed,iteration.timeline.timeScalechanges the Timeline's own speed only. It doesn't followthis.time.timeScale, and it doesn't change the tweens it starts: setthis.tweens.timeScalefor those.
Since 4.3, COMPLETE, and a repeat, wait until every event has run and every tween they started has finished. Tweens which repeat or loop forever aren't waited for. To act the moment the last event runs, give that event a run callback.
A Timeline runs in the Scene's update step, apart from the Clock: this.time.paused doesn't pause it, but pausing the Scene does. It's destroyed when the Scene shuts down.
Slow motion and pausing
Each system keeps its own time, so there's no single switch. For slow motion across a Scene:
- Also set
timeScaleon each Timeline and particle emitter you want slowed. - Arcade's
timeScaleis the inverse of the others: 2 is half speed. this.animsis the game's AnimationManager, soglobalTimeScalechanges every Scene. For one sprite, usesprite.anims.timeScale.this.scene.pause()stops the whole Scene update: timers, tweens, Timelines, physics and animations. It keeps rendering. See scenes.- To pause only some systems:
this.time.paused = true,this.tweens.pauseAll(),this.physics.pause().
Delta time
- Moving a fixed amount each frame (
x += 3) runs twice as fast on a 120 Hz screen. Usedelta, or use tweens and physics, which already do. deltais in ms and smoothed: it's the average of the last 10 frames (fps.deltaHistory), and a frame longer than1000 / fps.minms (200 ms) is replaced by the last normal one, so nothing jumps after a tab switch. The raw value isthis.game.loop.rawDelta.this.game.loop.actualFpsis the measured frame rate.
FPS limit
- Use
setFPSLimitrather than writinggame.loop.fpsLimit, which leaves its derived values stale. fps.target(60) doesn't cap the frame rate. Uselimit.- Before 4.3, game time ran faster than real time with
fps.limitset, such as 1.4 times with a limit of 91 on a 75 Hz display. A game tuned with a limit on 4.2 or earlier may feel slower in 4.3, because it now runs at the right speed.
Gotchas
- `repeat: 4` fires 5 times.
repeatcounts the extra fires after the first. - `this` in a `function` callback is the TimerEvent. Use an arrow function, or set
callbackScope: this. - `this.time.timeScale` only scales Timer Events. Tweens, Timelines, physics and animations each have their own time scale. See Slow motion.
- A Timeline starts paused. Call
play(). - A Timeline tween doesn't use the event's `target`. Give the tween config its own
targets. - Timers and Timelines don't survive a Scene restart. The Clock destroys its timers on shutdown, and Timelines are destroyed too. Make them again in
create.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/time-and-timers/SKILL.md
Popularity
- Repository stars
- 39,633
- Repository forks
- 7,130
- 7-day trend score
- 53
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Grok Build (Cursor)
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/phaserjs/phaser/time-and-timers)