The x-coordinate of the anchor point (0-1). Controls the origin point for rotation and scaling.
The y-coordinate of the anchor point (0-1). Controls the origin point for rotation and scaling.
The color of the particle as a 32-bit RGBA value. Combines tint and alpha into a single value.
The rotation of the particle in radians. Positive values rotate clockwise.
The horizontal scale factor of the particle. Values greater than 1 increase size, less than 1 decrease size.
The vertical scale factor of the particle. Values greater than 1 increase size, less than 1 decrease size.
The texture used to render this particle. All particles in a container should share the same base texture.
The x-coordinate of the particle in world space.
The y-coordinate of the particle in world space.
Static
defaultDefault options used when creating new particles. These values are applied when specific options aren't provided in the constructor.
// Override defaults globally
Particle.defaultOptions = {
...Particle.defaultOptions,
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
};
// New particles use modified defaults
const centeredParticle = new Particle(texture);
console.log(centeredParticle.anchorX); // 0.5
console.log(centeredParticle.alpha); // 0.8
The transparency of the particle. Values range from 0 (fully transparent) to 1 (fully opaque). Values outside this range are clamped.
// Create a semi-transparent particle
const particle = new Particle({
texture: Texture.from('particle.png'),
alpha: 0.5
});
// Fade out
particle.alpha *= 0.9;
// Fade in
particle.alpha = Math.min(particle.alpha + 0.1, 1);
// Values are clamped to valid range
particle.alpha = 1.5; // Becomes 1.0
particle.alpha = -0.5; // Becomes 0.0
// Animate transparency
app.ticker.add((delta) => {
const time = performance.now() / 1000;
particle.alpha = 0.5 + Math.sin(time) * 0.5; // Pulse between 0-1
});
The tint color of the particle. Can be set using hex numbers or CSS color strings. The tint is multiplied with the texture color to create the final particle color.
// Create a red particle
const particle = new Particle({
texture: Texture.from('particle.png'),
tint: 0xff0000
});
// Use CSS color strings
particle.tint = '#00ff00'; // Green
particle.tint = 'blue'; // Blue
// Animate tint color
app.ticker.add(() => {
const time = performance.now() / 1000;
// Cycle through hues
const hue = (time * 50) % 360;
particle.tint = `hsl(${hue}, 100%, 50%)`;
});
// Reset to white (no tint)
particle.tint = 0xffffff;
Represents a single particle within a particle container. This class implements the IParticle interface, providing properties and methods to manage the particle's position, scale, rotation, color, and texture.
The reason we use a particle over a sprite is that these are much lighter weight and we can create a lot of them without taking on the overhead of a full sprite.
Example