Skip to main content

AnimationCurve

Class

A curve that contains a set of keyframes and can evaluate values at specific timestamps.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v234

Index

Example

// Example of using Animation Curve

// creating keyframes
var A = AnimationCurve.createKeyFrame();
var B = AnimationCurve.createKeyFrame();

// creating AnimationCurve
var curve = AnimationCurve.create();
A.time = 0.0;
A.value = 0.0;

B.time = 1.0;
B.value = 1.0;

curve.addKeyframe(A);
curve.addKeyframe(B);
let idxB = curve.addKeyframe(B);

// evaluating value
var value = curve.evaluate(0.5);

Extends

Properties

keyFrameCount

readonly keyFrameCount: number

The number of keyframes in the animation curve.

Since

Lens Scripting Version 234

Methods

addKeyframe()

addKeyframe(frame?): void

Adds a keyframe to the curve. The curve takes a copy of the keyframe's data; to edit it afterwards, retrieve the live handle via AnimationCurve#getKeyFrame.

Parameters

ParameterType
frame?AnimationKeyFrame

Returns

void

Since

Lens Scripting Version 234


create()

static create(): AnimationCurve

Create new animation curve.

Returns

AnimationCurve

Since

Lens Scripting Version 234


createEasingCurve()

static createEasingCurve(startValue, endValue, x1, y1, x2, y2, time?): AnimationCurve

Creates curve based on CSS easing values. The optional time argument sets the end time of the curve; the curve spans from time 0 to time (defaults to 1.0).

Parameters

ParameterType
startValuenumber
endValuenumber
x1number
y1number
x2number
y2number
time?number

Returns

AnimationCurve

Since

Lens Scripting Version 234


createKeyFrame()

static createKeyFrame(): AnimationKeyFrame

Create new animation keyframe

Returns

AnimationKeyFrame

Since

Lens Scripting Version 234


evaluate()

evaluate(time): number

Evaluate value of the curve at specific point.

Parameters

ParameterType
timenumber

Returns

number

Since

Lens Scripting Version 234


getKeyFrame()

getKeyFrame(index): AnimationKeyFrame

Get the AnimationKeyFrame at the passed in index. The returned object is a live handle into the curve — editing its time, value, or tangent properties updates the curve directly.

Parameters

ParameterType
indexnumber

Returns

AnimationKeyFrame

Since

Lens Scripting Version 234


getTypeName()

static getTypeName(): TypeName<AnimationCurve>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<AnimationCurve>

Since

Lens Scripting Version 234

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


removeKeyFrame()

removeKeyFrame(t): void

Remove animation keyframe at specific timestamp. The closest keyframe will be deleted.

Parameters

ParameterType
tnumber

Returns

void

Since

Lens Scripting Version 234