Skip to content
pixi-silk
GitHub repository
Class

Spring

import { Spring } from 'pixi-silk';

Damped harmonic spring with unit mass, integrated in fixed 1/240 s sub-steps. stiffness and damping follow the usual UI spring convention. The defaults are 170 and 26.

Constructors#

Constructor#

new Spring(
   value?: number, 
   stiffness?: number, 
   damping?: number
): Spring;

Starts at rest at value, with its target there too.

Parameters#

ParameterTypeDefault value
valuenumber0
stiffnessnumber170
dampingnumber26

Returns#

Spring

Properties#

PropertyTypeDefault valueDescriptionDefined in
dampingnumberundefinedFriction. Lower bounces more. Default 26.motion.ts:38
stiffnessnumberundefinedPull towards the target. Higher is faster. Default 170.motion.ts:36
targetnumberundefinedValue the spring moves towards.motion.ts:32
valuenumberundefinedCurrent value.motion.ts:30
velocitynumber0Current speed, in units per second.motion.ts:34

Accessors#

settled#

Get Signature#

get settled(): boolean;

True once the spring is within 1e-4 of its target and its speed is below 1e-4.

Returns

boolean

Methods#

step()#

step(dtSeconds: number): number;

Advances the spring by dtSeconds, capped at 0.1 s so a stalled tab does not jump, and returns the new value.

Parameters#

ParameterType
dtSecondsnumber

Returns#

number