Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
2183 lines (1367 sloc) 56.6 KB

Colib API

Home > API

Index

Enumerations

Classes

Interfaces

Type aliases

Functions


Type aliases

ColorType

Ƭ ColorType: string | number | ColorRGB | ColorHSL | ColorHSV

Defined in color/color-types.ts:34

Composite type of all supported color formats.


Command

Ƭ Command: function

Defined in commands/common.ts:22

The base building block for all commands. This is what the CommandQueue and CommandScheduler update. Commands typically capture state, and are only safe to be invoked by a single queue/scheduler at once. Inside options, deltaTime is the time to update the command by. The command should modify deltaTime, subtracting the time it has consumed. The command sets the completed flag to true when it has completed, or false otherwise. Once the delegate has completed, the next call should restart it. If the operation is set to fast forward, the command should try to immediately complete.

Type declaration

▸(deltaTime: number, operation: CommandOperation): CommandState | void

Parameters:

Name Type
deltaTime number
operation CommandOperation

Returns: CommandState | void


CommandAct

Ƭ CommandAct: function

Defined in commands/common.ts:27

A one shot command. It doesn't take up any time, and completes immediately.

Type declaration

▸(): void

Returns: void


CommandCondition

Ƭ CommandCondition: function

Defined in commands/common.ts:32

A condition returns true or false, which can change the flow control for some commands.

Type declaration

▸(): boolean

Returns: boolean


CommandCoroutine

Ƭ CommandCoroutine: function

Defined in commands/common.ts:57

A coroutine command uses generators to produce a sequence of commands over time.

function* aCoroutine(): CommandIterator {
  yield wait(5);
  console.log('Now this is called');
  yield interval(t => console.log(t), 10);
  console.log('This is also called');
}

Type declaration

▸(): CommandIterator

Returns: CommandIterator


CommandFactory

Ƭ CommandFactory: function

Defined in commands/common.ts:42

A command factory creates a command.

Type declaration

▸(): Command

Returns: Command


CommandInterval

Ƭ CommandInterval: function

Defined in commands/common.ts:37

A interval command is executed over a period of time. The value t is normalized from 0 to 1.

Type declaration

▸(t: number): void

Parameters:

Name Type
t number

Returns: void


CommandIterator

Ƭ CommandIterator: IterableIterator<Command | undefined>

Defined in commands/common.ts:44


Ease

Ƭ Ease: function

Defined in ease.ts:7

An easing function takes an input value t where an uneased t ranges from 0 <= t <= 1 . Some easing functions, (such as BackEase returns values outside the range 0 <= t <= 1). For a given valid easing function, f(t), f(0) = 0 and f(1) = 1.

Type declaration

▸(t: number): number

Parameters:

Name Type
t number

Returns: number


Functions

averageComposite

averageComposite(...eases: Ease[]): Ease

Defined in ease.ts:61

Averages the output from several easing functions.

Parameters:

Name Type Description
Rest eases Ease[] The list of eases to average together.

Returns: Ease


cancelGlobalCommands

cancelGlobalCommands(): void

Defined in global.ts:53

Cancels all commands currently running on the globalScheduler and globalQueueGroup.

Returns: void


ceilStep

ceilStep(numSteps?: number): Ease

Defined in ease.ts:34

Quantises t into numSteps + 1 levels, using the ceil operation. This increases the average value of t over the duration of the ease.

Parameters:

Name Type Default value Description
Default value numSteps number 1 Must be >= 1

Returns: Ease


chainComposite

chainComposite(...eases: Ease[]): Ease

Defined in ease.ts:120

Eases a value, by pipelining it through several easing functions. The output of the first ease is used as input for the next.

Parameters:

Name Type
Rest eases Ease[]

Returns: Ease


changeFrom

changeFrom<T>(object: T, from: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:62

Tweens the properties on an object from a set of target values, using regular linear interpolation.

const queue = new CommandQueue();
const DURATION = 1;
const obj = { a: 10, b: 20, c: 30 };
const target = { b: 40, c: 60 };
queue.push(changeFrom(obj, target, DURATION));
queue.update(DURATION / 4);
console.log(obj); // { a: 10, b: 35, c: 52.5 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
from T The target to tween from.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


changeFromColor

changeFromColor<U>(ref: Ref<U> | ColorRGB | ColorHSL | ColorHSV, target: ColorType, commandDuration: number, lerpMode?: ColorLerpMode, ease?: Ease): Command

Defined in commands/color.ts:102

Changes a color, from an offset, to a current value, over time.

const queue = new CommandQueue();
const DURATION = 1.0;
const color = { r: 1, g: 1, b: 1, a: 1 };
queue.push(changeFromColor(color, 'rgb(50%,20%,10%,0.5)', DURATION));
queue.update(DURATION / 4);
console.log(color); // { r: 0.875, g: 0.8, b: 0.775, 0.875 }

Type parameters:

U : ColorType

Parameters:

Name Type Default value Description
ref Ref<U> | ColorRGB | ColorHSL | ColorHSV - A reference to the color to change.
target ColorType - The color to start from.
commandDuration number - The duration of the command
Default value lerpMode ColorLerpMode ColorLerpMode.RGB
Optional ease Ease - The ease to apply.

Returns: Command


changeFromNum

changeFromNum(ref: Ref<number>, startTarget: number, duration: number, ease?: Ease): Command

Defined in commands/number.ts:59

Sets a value to start, then tweens it back to it's original position.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(0);
queue.push(changeFromNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 75;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
startTarget number The value to tween from.
duration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


changeFromOffset

changeFromOffset<T>(object: T, offset: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:120

Tweens the properties on an object from an offset back to it's start position, using regular linear interpolation.

const queue = new CommandQueue();
const DURATION = 1;
const obj = { a: 10, b: 20, c: 30 };
const offset = { b: 40, c: 60 };
queue.push(changeFromOffset(obj, offset, DURATION));
queue.update(DURATION / 4);
console.log(obj); // { a: 10, b: 50, c: 75 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
offset T The offset to tween from.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


changeFromOffsetNum

changeFromOffsetNum(ref: Ref<number>, offset: number, duration: number, ease?: Ease): Command

Defined in commands/number.ts:132

Adds an offset to a value, then tweens it back to it's start position.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(10);
queue.push(changeFromOffsetNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 85;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
offset number The offset to tween from.
duration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


changeTo

changeTo<T>(object: T, target: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:33

Tweens the properties on an object to a set of target values, using regular linear interpolation.

const queue = new CommandQueue();
const DURATION = 1;
const obj = { a: 10, b: 20, c: 30 };
const target = { b: 40, c: 60 };
queue.push(changeTo(obj, target, DURATION));
queue.update(DURATION / 4);
console.log(obj); // { a: 10, b: 25, c: 37.5 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
target T The target to tween to.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


changeToColor

changeToColor<U>(ref: Ref<U> | ColorRGB | ColorHSL | ColorHSV, target: ColorType, commandDuration: number, lerpMode?: ColorLerpMode, ease?: Ease): Command

Defined in commands/color.ts:42

Changes a color to a target color over time.

const queue = new CommandQueue();
const DURATION = 1.0;
const color = { r: 1, g: 1, b: 1, a: 1 };
queue.push(changeToColor(color, 'rgb(50%,20%,10%,0.5)', DURATION));
queue.update(DURATION / 4);
console.log(color); // { r: 0.625, g: 0.4, b: 0.325, 0.625 }

Type parameters:

U : ColorType

Parameters:

Name Type Default value Description
ref Ref<U> | ColorRGB | ColorHSL | ColorHSV - A reference to the color to change.
target ColorType - The target color
commandDuration number - The duration of the command
Default value lerpMode ColorLerpMode ColorLerpMode.RGB
Optional ease Ease - The ease to apply.

Returns: Command


changeToNum

changeToNum(ref: Ref<number>, target: number, duration: number, ease?: Ease): Command

Defined in commands/number.ts:24

Tweens a number to an end value.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(0);
queue.push(changeToNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 25;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
target number The value the number should be at the end of the tween.
duration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


changeToOffset

changeToOffset<T>(object: T, offset: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:91

Tweens the properties on an object to an offset from it's start position, using regular linear interpolation.

const queue = new CommandQueue();
const DURATION = 1;
const obj = { a: 10, b: 20, c: 30 };
const offset = { b: 40, c: 60 };
queue.push(changeToOffset(obj, offset, DURATION));
queue.update(DURATION / 4);
console.log(obj); // { a: 10, b: 30, c: 45 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
offset T The offset to add to the start position.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


changeToOffsetNum

changeToOffsetNum(ref: Ref<number>, offset: number, duration: number, ease?: Ease): Command

Defined in commands/number.ts:94

Tweens a value towards it's current value plus an offset.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(10);
queue.push(changeToOffsetNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 35;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
offset number The offset to tween from the start.
duration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


chooseRandom

chooseRandom(...commands: (undefined | function)[]): Command

Defined in commands/common.ts:511

Chooses a random child command to perform. Re-evaluated on repeat.

const queue = new CommandQueue();
queue.push(
  chooseRandom(
    () => {
      console.log('a');
    },
    () => {
      console.log('b');
    },
    () => {
      console.log('c');
    }
  )
);
queue.update(0); // 'a' or 'b' or 'c'

Parameters:

Name Type Description
Rest commands (undefined | function)[] A list of commands to choose from at random. Only one command will be performed. Undefined commands can be passed. At least one command must be specified.

Returns: Command


consumeTime

consumeTime(): Command

Defined in commands/common.ts:571

Consumes all the time from the current update, but let's execution continue. Useful for compensating for loading bumps.

const queue = new CommandQueue();
queue.push(consumeTime(), waitForTime(0.1), () => {
  console.log('called');
});
queue.update(1000); // Nothing
queue.update(0.1); // "called"

Returns: Command


coroutine

coroutine(command: CommandCoroutine): Command

Defined in commands/common.ts:455

Creates a command which runs a coroutine.

Coroutines, (also known as generators in ES6), are methods which can be paused/resumed using the yield operator.

const queue = new CommandQueue();

function *coroutineWithNoArguments() {
  yield return waitForTime(2.0);
}

function *coroutineWithArguments(firstVal: number, secondVal: number, thirdVal: number) {
  console.log(firstVal);
  yield waitForTime(1.0); // You can return any Command here.
  console.log(secondValue);
  yield; // Wait a single frame.
  console.log(thirdVal);
}

queue.push(
  coroutine(coroutineWithNoArguments),
  coroutine(() => coroutineWithArguments(1, 2, 3))
);

Parameters:

Name Type Description
command CommandCoroutine The command to generate the coroutine.

Returns: Command


defer

defer(commandDeferred: CommandFactory): Command

Defined in commands/common.ts:544

Defers the creation of the Command until just before the point of execution.

const queue = new CommandQueue();
let loopCount = 0;
queue.push(
  repeat(
    3,
    defer(() => {
      console.log(`Loop ${loopCount}`);
      loopCount += 1;
      return waitForTime(loopCount);
    })
  )
);
queue.update(0); // "Loop 0"
queue.update(1); // "Loop 1"
queue.update(2); // "Loop 2"

Parameters:

Name Type Description
commandDeferred CommandFactory The action which will create the Command.

Returns: Command


dilateTime

dilateTime(dilationAmount: number, ...commands: Command[]): Command

Defined in commands/common.ts:596

Slows down, or increases the rate at which time flows through the given subcommands.

const queue = new CommandQueue();
queue.push(
  dilateTime(2, waitForTime(1), () => {
    console.log('called');
  })
);
queue.update(0.5); // "called"

Parameters:

Name Type Description
dilationAmount number The scale of the dilation to perform. For instance, a dilationAmount of 2 will make time flow twice as quickly. This number must be greater than 0.
Rest commands Command[] A list of commands to choose to dilate time for.

Returns: Command


elastic

elastic(amplitude?: number, period?: number): Ease

Defined in ease.ts:231

An ease with an elastic effect.

Parameters:

Name Type Default value Description
Default value amplitude number 1 The maximum amount of displacement caused by the elastic effect
Default value period number 0.3 How springy the elastic effect is.

Returns: Ease


flip

flip(inEase: Ease): Ease

Defined in ease.ts:146

Flips an ease about the x/y axis, so ease ins become ease outs etcs.

Parameters:

Name Type Description
inEase Ease The ease to flip

Returns: Ease


floorStep

floorStep(numSteps?: number): Ease

Defined in ease.ts:45

Quantises t into numSteps + 1 levels, using floor operation. This decreases the average value of t over the duration of the ease.

Parameters:

Name Type Default value Description
Default value numSteps number 1 Must be >= 1

Returns: Ease


globalQueueGroup

globalQueueGroup(maxDeltaTime?: number): CommandQueueGroup

Defined in global.ts:46

Retrieves the globalQueueGroup.

const queueGroup = globalQueueGroup();
const queue = queueGroup.createQueue();

Parameters:

Name Type Default value Description
Default value maxDeltaTime number MAX_DELTA_TIME_MS The most amount of time the global scheduler can update by between frames. In the browser, this is useful to prevent animations fast forwarding when resuming a backgrounded tab.

Returns: CommandQueueGroup A global, shared CommandQueueGroup for the current environment.


globalScheduler

globalScheduler(maxDeltaTime?: number): CommandScheduler

Defined in global.ts:30

Retrieves the globalScheduler.

const scheduler = globalScheduler();
const queue = scheduler.add(() => {
  console.log('Hello');
});

Parameters:

Name Type Default value Description
Default value maxDeltaTime number MAX_DELTA_TIME_MS The most amount of time the global scheduler can update by between frames. In the browser, this is useful to prevent animations fast forwarding when resuming a backgrounded tab.

Returns: CommandScheduler A global, shared CommandScheduler for the current environment.


hermite

hermite(startGradient?: number, endGradient?: number): Ease

Defined in ease.ts:345

A Hermite curve easing function. The Hermite curve is a cheap easing function, with adjustable gradients at it's endpoints.

Parameters:

Name Type Default value Description
Default value startGradient number 0 The gradient, (x/y), at the start of the ease. The closer this is to zero, the smoother the ease.
Default value endGradient number 0 The gradient (x/y), at the end of the ease. The closer this is to zero, the smoother the ease.

Returns: Ease


inBack

inBack(overshoot?: number): Ease

Defined in ease.ts:296

The in back ease is used to reverse a little, before shooting towards a target.

Parameters:

Name Type Default value Description
Default value overshoot number 0.2 The amount to overshoot the goal by.

Returns: Ease


inBounce

inBounce(): Ease

Defined in ease.ts:316

Returns: Ease


inCirc

inCirc(): Ease

Defined in ease.ts:281

Returns: Ease


inCubic

inCubic(): Ease

Defined in ease.ts:178

Returns: Ease


inElastic

inElastic(): Ease

Defined in ease.ts:253

Returns: Ease


inExpo

inExpo(): Ease

Defined in ease.ts:263

Returns: Ease


inHermite

inHermite(): Ease

Defined in ease.ts:359

Returns: Ease


inOutBack

inOutBack(overshoot?: number): Ease

Defined in ease.ts:312

The in back ease is used to overshoot a target.

Parameters:

Name Type Default value Description
Default value overshoot number 0.2 The amount to overshoot the goal by.

Returns: Ease


inOutBounce

inOutBounce(): Ease

Defined in ease.ts:336

Returns: Ease


inOutCirc

inOutCirc(): Ease

Defined in ease.ts:287

Returns: Ease


inOutCubic

inOutCubic(): Ease

Defined in ease.ts:184

Returns: Ease


inOutEase

inOutEase(inEase: Ease, outEase: Ease): Ease

Defined in ease.ts:133

Combines two easing functions. The inEase parameter maps to the range 0.0 <= t < 0.5, outEase maps to the range 0.5 <= t < 1.0

Parameters:

Name Type Description
inEase Ease The ease in function
outEase Ease The ease out function

Returns: Ease


inOutElastic

inOutElastic(): Ease

Defined in ease.ts:259

Returns: Ease


inOutExpo

inOutExpo(): Ease

Defined in ease.ts:277

Returns: Ease


inOutHermite

inOutHermite(): Ease

Defined in ease.ts:367

Returns: Ease


inOutPolynomial

inOutPolynomial(power: number): Ease

Defined in ease.ts:164

Parameters:

Name Type
power number

Returns: Ease


inOutQuad

inOutQuad(): Ease

Defined in ease.ts:174

Returns: Ease


inOutQuart

inOutQuart(): Ease

Defined in ease.ts:194

Returns: Ease


inOutQuint

inOutQuint(): Ease

Defined in ease.ts:204

Returns: Ease


inOutSin

inOutSin(): Ease

Defined in ease.ts:222

Returns: Ease


inPolynomial

inPolynomial(power: number): Ease

Defined in ease.ts:154

Creates a polynomial easing function, (quadratic, cubic etc).

Parameters:

Name Type Description
power number The power of the easing function. Must be > 0 .

Returns: Ease


inQuad

inQuad(): Ease

Defined in ease.ts:168

Returns: Ease


inQuart

inQuart(): Ease

Defined in ease.ts:188

Returns: Ease


inQuint

inQuint(): Ease

Defined in ease.ts:198

Returns: Ease


inSin

inSin(): Ease

Defined in ease.ts:211

Eases using a trigonometric functions.

Returns: Ease


interruptable

interruptable(command: Command, onInterrupt: function): Command

Defined in commands/common.ts:87

Interruptable commands are useful for situations where a command is waiting for an external action to finish, but a queue running the command wants to fast foward. For example, consider a command to play an audio clip. The command starts the Audio, then polls waiting for it to finish. Suddenly a queue running the command is told to runToEnd. In this case, the onInterrupt action is called, which stops the audio source and performs cleanup. The command then finishes, and the queue continues.

const queue = new CommandQueue();
const audioPlayer = new AudioPlayer(audioClip);
queue.push(
 interruptable(
   defer(() => {
     console.log('Playing');
     audioPlayer.play();
     return waitForTime(audioClip.length);
   }, () => {
     console.log('Stopped');
     audioPlayer.stop();
   })
);
queue.update(1.0); // Playing
queue.runToEnd(); // Stopped

Parameters:

Name Type Description
command Command The command to make interruptable
onInterrupt function The action to perform if the

Returns: Command


interval

interval(command: CommandInterval, duration: number, ease?: Ease): Command

Defined in commands/common.ts:140

Runs a command over an interval of time.

const DURATION = 5;
const queue = new CommandQueue();
queue.push(
  interval(t => {
    console.log(t);
  }, DURATION)
);
queue.update(1); // 0.2
queue.update(2); // 0.6
queue.update(2); // 1

Parameters:

Name Type Description
command CommandInterval The command to execute.
duration number The duration of time to apply the command over. Must be greater than or equal to 0.
Optional ease Ease An easing function to apply to the t parameter of a CommandDuration. If undefined, linear easing is used.

Returns: Command


isColorHSL

isColorHSL(value: any): boolean

Defined in color/color-types.ts:72

Type guard for determining whether a color is a ColorHSL object.

Parameters:

Name Type Description
value any The value to test.

Returns: boolean


isColorHSV

isColorHSV(value: any): boolean

Defined in color/color-types.ts:56

Type guard for determining whether a color is a ColorHSV object.

Parameters:

Name Type Description
value any The value to test.

Returns: boolean


isColorRGB

isColorRGB(value: any): boolean

Defined in color/color-types.ts:40

Type guard for determining whether a color is a ColorRGB object.

Parameters:

Name Type Description
value any The value to test.

Returns: boolean


linear

linear(): Ease

Defined in ease.ts:13

The default ease. It doesn't modify the value of t.

Returns: Ease


mapParallel

mapParallel<T>(items: Iterable<T>, factory: function): Command

Defined in commands/functional.ts:23

Maps a collection of values to a series of commands run in parallel.

const items = ['called 1', 'called 2', 'called 3'];
const queue = new CommandQueue();
queue.push(
  mapParallel(items, item => {
    return sequence(waitForTime(1), () => {
      console.log(item);
    });
  })
);
queue.update(1); // "called 1" "called 2" "called 3"

Type parameters:

T

Parameters:

Name Type Description
items Iterable<T> The collection of items
factory function A factory function which converts each item to a command

Returns: Command


mapSequential

mapSequential<T>(items: Iterable<T>, factory: function): Command

Defined in commands/functional.ts:49

Maps a collection of values to a series of commands run sequentially.

const items = ['called 1', 'called 2', 'called 3'];
const queue = new CommandQueue();
queue.push(
  mapSequential(items, item => {
    return sequence(waitForTime(1), () => {
      console.log(item);
    });
  })
);
queue.update(1); // "called 1"
queue.update(1); // "called 2"
queue.update(1); // "called 3"

Type parameters:

T

Parameters:

Name Type Description
items Iterable<T> The collection of items
factory function A factory function which converts each item to a command

Returns: Command


none

none(): Command

Defined in commands/common.ts:118

A command which does nothing. Can be useful as a return value.

const queue = new CommandQueue();
queue.push(none(), () => {
  console.log('called');
});
queue.update(0); // Called

Returns: Command


outBack

outBack(overshoot?: number): Ease

Defined in ease.ts:304

The in back ease is used to overshoot a target.

Parameters:

Name Type Default value Description
Default value overshoot number 0.2 The amount to overshoot the goal by.

Returns: Ease


outBounce

outBounce(): Ease

Defined in ease.ts:333

Returns: Ease


outCirc

outCirc(): Ease

Defined in ease.ts:284

Returns: Ease


outCubic

outCubic(): Ease

Defined in ease.ts:181

Returns: Ease


outElastic

outElastic(): Ease

Defined in ease.ts:256

Returns: Ease


outExpo

outExpo(): Ease

Defined in ease.ts:274

Returns: Ease


outHermite

outHermite(): Ease

Defined in ease.ts:363

Returns: Ease


outPolynomial

outPolynomial(power: number): Ease

Defined in ease.ts:161

Parameters:

Name Type
power number

Returns: Ease


outQuad

outQuad(): Ease

Defined in ease.ts:171

Returns: Ease


outQuart

outQuart(): Ease

Defined in ease.ts:191

Returns: Ease


outQuint

outQuint(): Ease

Defined in ease.ts:201

Returns: Ease


outSin

outSin(): Ease

Defined in ease.ts:219

Returns: Ease


parallel

parallel(...commands: Command[]): Command

Defined in commands/common.ts:272

A parallel command executes several commands in parallel. It finishes when the last command has finished.

const queue = new CommandQueue();
queue.push(
   parallel(
    () => { console.log('called 1'); }
    waitForTime(1),
    () => { console.log('called 2'); }
  )
);
queue.update(0); // 'called 1' 'called 2'

Parameters:

Name Type Description
Rest commands Command[] The commands to execute.

Returns: Command


repeat

repeat(repeatCount: number, ...commands: Command[]): Command

Defined in commands/common.ts:364

The repeat command repeats a delegate a given number of times.

const queue = new CommandQueue();
queue.push(
  repeat(3, () => {
    console.log('called');
  })
);
queue.update(10); // 'called' x 3

Parameters:

Name Type Description
repeatCount number The number of times to repeat the given command. Must be > 0.
Rest commands Command[] The commands to repeat. All of the basic commands are repeatable without side-effects.

Returns: Command


repeatForever

repeatForever(...commands: Command[]): Command

Defined in commands/common.ts:411

Repeats a command forever. Make sure that the commands you are repeating will consume some time, otherwise this will create an infinite loop. RepeatForever can be escaped by calling runToEnd on the CommandQueue, or using CommandOperation.FastForward.

const queue = new CommandQueue();
queue.push(
  repeatForever(waitForTime(1), () => {
    console.log('called');
  })
);
queue.update(10); // 'called' x 10
queue.runToEnd(); // repeatForever will be forced to complete

Parameters:

Name Type Description
Rest commands Command[] The commands to execute.

Returns: Command


roundStep

roundStep(numSteps?: number): Ease

Defined in ease.ts:21

Quantises t into numSteps + 1 levels, using the round operation.

Parameters:

Name Type Default value Description
Default value numSteps number 1 Must be >= 1

Returns: Ease


scaleBy

scaleBy<T>(object: T, scaleFactor: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:149

Scales up the properties on an object by scaleFactor

const queue = new CommandQueue();
const DURATION = 1;
const obj = { x: 10, y: 20, z: 30 };
const scaleFactor = { x: 2, y: 3, z: 4 };
queue.push(scaleBy(obj, scaleFactor, DURATION));
queue.update(DURATION);
console.log(obj); // { x: 20, y: 60, z: 120 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
scaleFactor T The scale factor to apply to the object. This should have matching properties.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


scaleByNum

scaleByNum(ref: Ref<number>, scaleFactor: number, commandDuration: number, ease?: Ease): Command

Defined in commands/number.ts:169

Tween that scales up a value by scaleFactor.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(4);
queue.push(scaleByNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 99;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
scaleFactor number How much to scale up the value by.
commandDuration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


scaleFrom

scaleFrom<T>(object: T, scaleFactor: T, commandDuration: number, ease?: Ease): Command

Defined in commands/object.ts:178

Immediately scales up the properties on an object by scaleFactor, then tweens back to the original scale.

const queue = new CommandQueue();
const DURATION = 1;
const obj = { x: 10, y: 20, z: 30 };
const scaleFactor = { x: 2, y: 3, z: 4 };
queue.push(scaleFrom(obj, scaleFactor, DURATION));
queue.update(DURATION / 4);
console.log(obj); // { x: 17.5, y: 50, z: 97.5 }

Type parameters:

T

Parameters:

Name Type Description
object T The object to tween the properties of.
scaleFactor T The scale factor to apply to the object. This should have matching properties.
commandDuration number The duration of the command.
Optional ease Ease The ease to apply

Returns: Command


scaleFromNum

scaleFromNum(ref: Ref<number>, scaleFactor: number, duration: number, ease?: Ease): Command

Defined in commands/number.ts:205

Multiplies a value by scaleFactor, then tweens it from that value back to it's starting value.

const DURATION = 1.0;
const queue = new CommandQueue();
const numRef = Ref.create(4);
queue.push(scaleFromNum(numRef, 100, DURATION));
queue.update(DURATION / 4);
console.log(numRef.value); // 301;

Parameters:

Name Type Description
ref Ref<number> A reference to the number to tween.
scaleFactor number How much to scale up the value by.
duration number The duration of the tween.
Optional ease Ease The ease to use for the tween.

Returns: Command


sequence

sequence(...commands: Command[]): Command

Defined in commands/common.ts:320

A sequence command executes several commands sequentially.

const queue = new CommandQueue();
queue.push(
  sequence(waitForTime(1), () => {
    console.log('called');
  })
);
queue.update(1); // 'called'

Parameters:

Name Type Description
Rest commands Command[] A parameter list of commands to execute sequentially.

Returns: Command


sequentialComposite

sequentialComposite(...eases: Ease[]): Ease

Defined in ease.ts:77

Sequentially triggers easing functions. For instance, if we have 3 easing functions, 0 <= t < 0.33 is handled by first easing function 0.33 <= t < 0.66 by second, and 0.66 <= t <= 1.0 by third.

Parameters:

Name Type Description
Rest eases Ease[] The list of eases to chain together.

Returns: Ease


smooth

smooth(): Ease

Defined in ease.ts:371

Returns: Ease


waitForFrames

waitForFrames(frameCount: number): Command

Defined in commands/common.ts:234

Waits a specified number of calls to update. This ignores time althogether.

const queue = new CommandQueue();
queue.push(waitForFrames(2), () => {
  console.log('called');
});
queue.update(1000);
queue.update(1000);
queue.update(0); // called

Parameters:

Name Type Description
frameCount number The number of frames to wait. Must be > 0.

Returns: Command


waitForTime

waitForTime(duration: number): Command

Defined in commands/common.ts:196

Waits until a given amount of time has elapsed.

const queue = new CommandQueue();
queue.push(waitForTime(10), () => {
  console.log('called');
});
queue.update(5);
queue.update(5); // called

Parameters:

Name Type Description
duration number The duration of time to wait. Must be greater than or equal to 0.

Returns: Command


weightedComposite

weightedComposite(...eases: WeightedEaseConfig[]): Ease

Defined in ease.ts:104

Averages the output of several easing function using a weighting for each.

Parameters:

Name Type Description
Rest eases WeightedEaseConfig[] The list of eases to average together.

Returns: Ease


You can’t perform that action at this time.