Whether or not this ticker should invoke the method start automatically when a listener is added.
// Default behavior (manual start)
const ticker = new Ticker();
ticker.autoStart = false;
ticker.add(() => {
// Won't run until ticker.start() is called
});
// Auto-start behavior
const autoTicker = new Ticker();
autoTicker.autoStart = true;
autoTicker.add(() => {
// Runs immediately when added
});
Scalar time elapsed in milliseconds from last frame to this frame. Provides precise timing for animations and updates.
This value is capped by setting minFPS and is scaled with speed.
If the platform supports DOMHighResTimeStamp, this value will have a precision of 1 µs.
Defaults to target frame time
The cap may be exceeded by scaling.
Time elapsed in milliseconds from last frame to this frame. Provides raw timing information without modifications.
Opposed to what the scalar deltaTime is based, this value is neither capped nor scaled.
If the platform supports DOMHighResTimeStamp, this value will have a precision of 1 µs.
Defaults to target frame time
The last time update was invoked. Used for calculating time deltas between frames.
This value is also reset internally outside of invoking update, but only when a new animation frame is requested.
If the platform supports DOMHighResTimeStamp, this value will have a precision of 1 µs.
Factor of current deltaTime. Used to scale time for slow motion or fast-forward effects.
Static
targetTarget frame rate in frames per millisecond. Used for converting deltaTime to a scalar time delta.
// Default is 0.06 (60 FPS)
console.log(Ticker.targetFPMS); // 0.06
// Calculate target frame duration
const frameDuration = 1 / Ticker.targetFPMS; // ≈ 16.67ms
// Use in custom timing calculations
const deltaTime = elapsedMS * Ticker.targetFPMS;
The number of listeners on this ticker, calculated by walking through linked list.
// Check number of active listeners
const ticker = new Ticker();
console.log(ticker.count); // 0
// Add some listeners
ticker.add(() => {});
ticker.add(() => {});
console.log(ticker.count); // 2
// Check after cleanup
ticker.destroy();
console.log(ticker.count); // 0
The frames per second at which this ticker is running. The default is approximately 60 in most modern browsers.
Manages the minimum amount of milliseconds required to elapse between invoking update.
This will effect the measured value of FPS.
If it is set to 0
, then there is no limit; PixiJS will render as many frames as it can.
Otherwise it will be at least minFPS
// Set minimum acceptable frame rate
const ticker = new Ticker();
ticker.maxFPS = 60; // Never go above 60 FPS
// Use with maxFPS for frame rate clamping
ticker.minFPS = 30;
ticker.maxFPS = 60;
// Monitor delta capping
ticker.add(() => {
// Delta time will be capped based on maxFPS
console.log(`Delta time: ${ticker.deltaTime}`);
});
Manages the maximum amount of milliseconds allowed to elapse between invoking update.
This value is used to cap deltaTime, but does not effect the measured value of FPS.
When setting this property it is clamped to a value between
0
and Ticker.targetFPMS * 1000
.
// Set minimum acceptable frame rate
const ticker = new Ticker();
ticker.minFPS = 30; // Never go below 30 FPS
// Use with maxFPS for frame rate clamping
ticker.minFPS = 30;
ticker.maxFPS = 60;
// Monitor delta capping
ticker.add(() => {
// Delta time will be capped based on minFPS
console.log(`Delta time: ${ticker.deltaTime}`);
});
Static
sharedThe shared ticker instance used by AnimatedSprite and by VideoSource to update animation frames / video textures.
It may also be used by Application if created with the sharedTicker
option property set to true.
The property autoStart is set to true
for this instance.
Please follow the examples for usage, including how to opt-out of auto-starting the shared ticker.
import { Ticker } from 'pixi.js';
const ticker = Ticker.shared;
// Set this to prevent starting this ticker when listeners are added.
// By default this is true only for the Ticker.shared instance.
ticker.autoStart = false;
// FYI, call this to ensure the ticker is stopped. It should be stopped
// if you have not attempted to render anything yet.
ticker.stop();
// Call this when you are ready for a running shared ticker.
ticker.start();
import { autoDetectRenderer, Container } from 'pixi.js';
// You may use the shared ticker to render...
const renderer = autoDetectRenderer();
const stage = new Container();
document.body.appendChild(renderer.view);
ticker.add((time) => renderer.render(stage));
// Or you can just update it manually.
ticker.autoStart = false;
ticker.stop();
const animate = (time) => {
ticker.update(time);
renderer.render(stage);
requestAnimationFrame(animate);
};
animate(performance.now());
Static
systemAdvanced
The system ticker instance used by PrepareBase for core timing
functionality that shouldn't usually need to be paused, unlike the shared
ticker which drives visual animations and rendering which may want to be paused.
The property autoStart is set to true
for this instance.
Register a handler for tick events. Calls continuously unless it is removed or the ticker is stopped.
The listener function to be added for updates
Optional
context: TThe listener context
The priority for emitting (default: UPDATE_PRIORITY.NORMAL)
This instance of a ticker
// Basic update handler
ticker.add((ticker) => {
// Update every frame
sprite.rotation += 0.1 * ticker.deltaTime;
});
// With specific context
const game = {
update(ticker) {
this.physics.update(ticker.deltaTime);
}
};
ticker.add(game.update, game);
// With priority
ticker.add(
(ticker) => {
// Runs before normal priority updates
physics.update(ticker.deltaTime);
},
undefined,
UPDATE_PRIORITY.HIGH
);
Add a handler for the tick event which is only executed once on the next frame.
The listener function to be added for one update
Optional
context: TThe listener context
The priority for emitting (default: UPDATE_PRIORITY.NORMAL)
This instance of a ticker
// Basic one-time update
ticker.addOnce(() => {
console.log('Runs next frame only');
});
// With specific context
const game = {
init(ticker) {
this.loadResources();
console.log('Game initialized');
}
};
ticker.addOnce(game.init, game);
// With priority
ticker.addOnce(
() => {
// High priority one-time setup
physics.init();
},
undefined,
UPDATE_PRIORITY.HIGH
);
Destroy the ticker and don't use after this. Calling this method removes all references to internal events.
// Clean up with active listeners
const ticker = new Ticker();
ticker.add(() => {});
ticker.destroy(); // Removes all listeners
Removes any handlers matching the function and context parameters. If no handlers are left after removing, then it cancels the animation frame.
The listener function to be removed
Optional
context: TThe listener context to be removed
This instance of a ticker
// Basic removal
const onTick = () => {
sprite.rotation += 0.1;
};
ticker.add(onTick);
ticker.remove(onTick);
// Remove with context
const game = {
update(ticker) {
this.physics.update(ticker.deltaTime);
}
};
ticker.add(game.update, game);
ticker.remove(game.update, game);
// Remove all matching handlers
// (if same function was added multiple times)
ticker.add(onTick);
ticker.add(onTick);
ticker.remove(onTick); // Removes all instances
Starts the ticker. If the ticker has listeners a new animation frame is requested at this point.
// Basic manual start
const ticker = new Ticker();
ticker.add(() => {
// Animation code here
});
ticker.start();
Stops the ticker. If the ticker has requested an animation frame it is canceled at this point.
Triggers an update.
An update entails setting the current elapsedMS, the current deltaTime, invoking all listeners with current deltaTime, and then finally setting lastTime with the value of currentTime that was provided.
This method will be called automatically by animation frame callbacks if the ticker instance has been started and listeners are added.
The current time of execution (defaults to performance.now())
A Ticker class that runs an update loop that other objects listen to. Used for managing animation frames and timing in a PixiJS application.
It provides a way to add listeners that will be called on each frame, allowing for smooth animations and updates.
Animation frames are requested only when necessary, e.g., when the ticker is started and the emitter has listeners.
Example
See