Skip to content

SpawnBehavior<DataType, ParticleType>

Behavior used to control the spawning shape and initial direction of particles.

Behavior supports four shapes, a point shape where particles spawn from a single point, a line shape where particles spawn along a line, a rectangle shape where particles spawn within a rectangle area, and a circle shape where particles spawn within a circular area.

See

SpawnBehaviorConfig for configuration options.

Examples

ts
// Spawn particles from a point with an initial upward direction.
spawnBehavior.applyConfig({
    shape: "point",
    direction: { x: 0, y: -1 },
});
ts
// Spawn particles along a horizontal line of
//  length 200 with no initial direction.
spawnBehavior.applyConfig({
    shape: "line",
    length: 200,
    direction: { x: 0, y: 0 },
});
ts
// Spawn particles within a rectangle of width 100 and
//  height 50 with an initial rightward direction.
spawnBehavior.applyConfig({
    shape: "rectangle",
    width: 100,
    height: 50,
    direction: { x: 1, y: 0 },
});
ts
// Spawn particles within a circle of outer radius 75 and
//  inner radius 25 with no initial direction.
spawnBehavior.applyConfig({
    shape: "circle",
    outerRadius: 75,
    innerRadius: 25,
    direction: { x: 0, y: 0 },
});

Extends

Type Parameters

DataType

DataType extends BaseParticleData = 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 SpawnBehavior<DataType, ParticleType>(emitter): SpawnBehavior<DataType, ParticleType>;

Creates a new instance of the behavior.

Parameters

emitter

Emitter<DataType, ParticleType>

Emitter instance this behavior belongs to.

Returns

SpawnBehavior<DataType, ParticleType>

Inherited from

EmitterBehavior.constructor

Accessors

direction

Get Signature

ts
get direction(): PointData;

Initial direction vector for spawned particles.

Returns

PointData

Set Signature

ts
set direction(value): void;
Parameters
value

PointData

Returns

void


height

Get Signature

ts
get height(): number;

Height of the spawn shape (for rectangle shape).

Returns

number

Set Signature

ts
set height(value): void;
Parameters
value

number

Returns

void


innerRadius

Get Signature

ts
get innerRadius(): number;

Inner radius of the spawn shape (for circle shape).

Returns

number

Set Signature

ts
set innerRadius(value): void;
Parameters
value

number

Returns

void


origin

Get Signature

ts
get origin(): PointData;

Origin (parent-local) position used as the center/offset for particle spawning.

This value is added to the shape-generated spawn coordinates in init. For the point shape, particles spawn exactly at this position.

This is relative to the parent transform (not a world-space position).

Returns

PointData

Set Signature

ts
set origin(value): void;
Parameters
value

PointData

Returns

void


outerRadius

Get Signature

ts
get outerRadius(): number;

Outer radius of the spawn shape (for circle shape).

Returns

number

Set Signature

ts
set outerRadius(value): void;
Parameters
value

number

Returns

void


shape

Get Signature

ts
get shape(): SpawnShape;

Current spawn shape used by the behavior.

Returns

SpawnShape

Set Signature

ts
set shape(value): void;
Parameters
value

SpawnShape

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

InitBehavior.updateOrder

Overrides

EmitterBehavior.updateOrder


width

Get Signature

ts
get width(): number;

Width of the spawn shape (for rectangle and line shapes).

Returns

number

Set Signature

ts
set width(value): void;
Parameters
value

number

Returns

void

Methods

applyConfig()

ts
applyConfig(config): void;

Reset the behavior and apply the provided configuration.

Parameters

config

SpawnBehaviorConfig

Behavior configuration.

Returns

void

Implementation of

InitBehavior.applyConfig

Overrides

EmitterBehavior.applyConfig


getConfig()

ts
getConfig(): SpawnBehaviorConfig;

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

Returns

SpawnBehaviorConfig

Behavior configuration object or undefined if inactive.

Implementation of

InitBehavior.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

InitBehavior.reset

Overrides

EmitterBehavior.reset