Skip to main content

Class: ModuleBuilder

index.ModuleBuilder

Represents a builder for particle modules. Returns an evaluatable module function, that can be consumed by emitters.

remarks Not all properties can be driven. TypeScript will validate this at compile time, but no internal validation is performed due to performance reasons. Also, note that the driving factor is "lifetime" by default.

example

new ModuleBuilder()    .drive("size")    .by((t) => t * 2)    .through("lifetime")    .build();

Constructors#

constructor#

• new ModuleBuilder()

Methods#

build#

â–¸ build(): ModuleFunction

Consumes the builder and returns an evaluatable module function.

remarks Note that you need to specify the driving key and value, otherwise an error will be thrown.

Returns#

ModuleFunction

Defined in#

systems/modules.ts:144


by#

â–¸ by<TDriver>(driver): ModuleBuilder

Specifies the value to drive the module behaviour by. This can be a constant, a spline or an evaluable function. Note that in the last case, the driving factor is passed as a parameter.

Type parameters#

NameType
TDriverextends DrivableType

Parameters#

NameType
driverModuleDriverValue<TDriver>

Returns#

ModuleBuilder

The chained builder instance.

Defined in#

systems/modules.ts:108


drive#

â–¸ drive<TKey>(key): ModuleBuilder

Specifies the key in the particle that should be driven.

remarks Note that not all of a particle's properties are drivable through modules. If you need full control of a particle inside of a module, you can use a module function directly.

Type parameters#

NameType
TKeyextends "size" | "rotation" | "color" | "opacity"

Parameters#

NameType
keyTKey

Returns#

ModuleBuilder

The chained builder instance.

Defined in#

systems/modules.ts:86


relative#

â–¸ relative(isRelative?): ModuleBuilder

Specifies that the module function is supposed to act relative to the properties initial value.

remarks Note that this is only possible if an "initial*" property exists on the particle object. The operation applied to the initial and new value is dependant on their type:

  • Vector: Both vectors are added.
  • number: Both numbers are multiplied.

For more advanced relative customizations, consider using the particle object in the driver value function instead, like:

.by((t, p) => p.initialSize + t * 2);

Parameters#

NameTypeDefault value
isRelativebooleantrue

Returns#

ModuleBuilder

Defined in#

systems/modules.ts:132


through#

â–¸ through(factor): ModuleBuilder

Specifies the factor to drive the evaluated value by. Supports "lifetime" and "size".

Parameters#

NameType
factorDrivableFactor

Returns#

ModuleBuilder

The chained builder instance.

Defined in#

systems/modules.ts:96