Methods

getPromiseResults(promises, [progressResolve], [progressReject])

Utility function that returns a promise that resolves after the given list of promises finishes its work.

Parameters

Return Value

A promise that is never rejected and resolves when all of the promises are each resolved or rejected. The result of the promise will be an object with three keys:

(Type: Promise)

getPromiseResultsAll(promises, [progressResolve], [progressReject])

Utility function that returns a promise that resolves or is rejected after the given list of promises finishes its work.

Parameters

Return Value

A promise that is resolved when all of the promises are each resolved; the result will be an array of results from those promises, in the order in which those promises were listed. Will be rejected if any of the promises is rejected; the result will be an object as specified in getPromiseResults. (Type: Promise)

getTimePosition(timer, timeInMs, intervalInMs)

Gets the position of a time value within an interval. This is useful for doing animation cycles lasting a certain number of seconds, such as rotating a shape in a 5-second cycle. This method may be called any number of times each frame.

Parameters

Return Value

A value in the range [0, 1), where closer to 0 means "timeInMs" lies closer to the start, and closer to 1 means closer to the end of the interval. If an initial time wasn't set, returns 0. (Type: number)

Examples

The following code sets an angle of rotation, in degrees, such that an object rotated with the angle does a 360-degree turn in 5 seconds (5000 milliseconds). The variable time is assumed to be a time value in milliseconds, such as the parameter of a requestAnimationFrame() callback method.

var angle = 360 * getTimePosition(timer, time, 5000);

newFrames(timer, timeInMs)

Returns the number of frame-length intervals that occurred since the last known time, where a frame's length is 1/60 of a second. This method should be called only once each frame.

Parameters

Return Value

The number of frame-length intervals relative to the last known time held in the parameter "timer". The number can include fractional frames. If an initial time or last known time wasn't set, returns 0. (Type: number)

toGLColor(r, [g], [b], [a])

Creates a 4-element array representing a color. Each element can range from 0 to 1 and specifies the red, green, blue or alpha component, respectively. This method also converts HTML and CSS colors to 4-element RGB colors. The following lists the kinds of colors accepted:

For more information, see the "Color Strings" tutorial.

Parameters

Return Value

The color as a 4-element array; if the color is invalid, returns [0,0,0,0], or transparent black. Numbers less than 0 are clamped to 0, and numbers greater than 1 are clamped to 1. (Type: Array.<number>)

Back to documentation index.