Skip to content

ColorBehavior<DataType, ParticleType>

Behavior used to control the color tint of particles over their lifetime.

Behavior supports three modes, a static mode where a single value is applied to all particles, a list mode where values are interpolated over the particle's lifetime based on a provided list, and a random mode where a random value from the list is applied to the particle upon initialization.

See

Example

ts
// Apply a static tint to all particles.
alphaBehavior.applyConfig({
    value: "#ff00ff",
});

// Interpolate particle tint from white to black over lifetime.
alphaBehavior.applyConfig({
    listData: [
        { time: 0.0, value: "#ffffff" },
        { time: 1.0, value: "#000000" },
    ],
    mode: "list",
});

// Assign a random tint value between the two stops.
alphaBehavior.applyConfig({
    listData: [
        { time: 0.0, value: "#ff00ff" },
        { time: 1.0, value: "#00ff00" },
    ],
    mode: "random",
});

Extends

Type Parameters

DataType

DataType extends BaseParticleData

Type describing the data object stored on particles.

ParticleType

ParticleType extends IEmitterParticle<DataType> = IEmitterParticle<DataType>

Type describing the particle used within the emitter.

Implements

Constructors

Constructor

ts
new ColorBehavior<DataType, ParticleType>(emitter): ColorBehavior<DataType, ParticleType>;

Creates new instance of ColorBehavior.

Parameters

emitter

Emitter<DataType, ParticleType>

Emitter instance this behavior belongs to.

Returns

ColorBehavior<DataType, ParticleType>

Overrides

EmitterBehavior.constructor

Accessors

list

Get Signature

ts
get list(): ColorList;

Color list used to interpolate tint values over particle lifetime.

A behavior will always have a list, even when not using list-based configuration, but the list might not be initialized and will be empty in that case.

Returns

ColorList


mode

Get Signature

ts
get mode(): "static" | "list" | "random";

Mode currently used by the behavior.

Returns

"static" | "list" | "random"

Set Signature

ts
set mode(value): void;
Parameters
value

"static" | "list" | "random"

Returns

void


staticValue

Get Signature

ts
get staticValue(): string;

Tint value applied to all particles in static mode.

Returns

string

Set Signature

ts
set staticValue(value): void;
Parameters
value

string

Returns

void


updateOrder

Get Signature

ts
get updateOrder(): BehaviorOrder;

Defines at which step of the update cycle the behavior is applied.

  • initial: Earliest step, useful when other behaviors depend on this behavior.
  • normal: Default step for most behaviors.
  • late: Latest step, useful for behaviors that should override others or depend on their properties.
Returns

BehaviorOrder

Implementation of

UpdateBehavior.updateOrder

Overrides

EmitterBehavior.updateOrder

Methods

applyConfig()

ts
applyConfig(config): void;

Reset the behavior and apply the provided configuration.

Parameters

config

ColorBehaviorConfig

Behavior configuration.

Returns

void

Implementation of

UpdateBehavior.applyConfig

Overrides

EmitterBehavior.applyConfig


getConfig()

ts
getConfig():
  | ColorBehaviorConfig
  | undefined;

Retrieve the current behavior properties as a configuration object. If the behavior is inactive, undefined is returned.

Returns

| ColorBehaviorConfig | undefined

Behavior configuration object or undefined if inactive.

Implementation of

UpdateBehavior.getConfig

Overrides

EmitterBehavior.getConfig


init()

ts
init(particle): void;

Initialize the particle.

Parameters

particle

ParticleType

Particle to initialize.

Returns

void

Implementation of

InitBehavior.init


reset()

ts
protected reset(): void;

Reset the behavior to its default state.

Returns

void

Implementation of

UpdateBehavior.reset

Overrides

EmitterBehavior.reset


update()

ts
update(particle): void;

Updates the particle.

Parameters

particle

ParticleType

Particle to update.

Returns

void

Implementation of

UpdateBehavior.update