Skip to main content

Motion

Since version 4.0.0

Interpolator between two values with duration

class Motion

Properties

Whether the interpolation is in active state.

Duration of the interpolation

Easing function of the interpolation

End(to) value of interpolation

Whether to loop interpolation on finish

Interpolation progress value (0 ~ 1)

Range of the interpolation

Start(from) value of interpolation

Current interpolated value

Methods

Add delta to start & end and current value.

Set start, end to the given value and set progress to 0.

Set current value to start, and end to current value + delta, then reset progress to 0.

Set new range of the interpolation.

Update motion and progress it by given deltaTime

Constructor

Create new instance.
new Motion(options: { duration: undefined | number; easing: undefined | ((x: number) => number); loop: undefined | boolean; range: undefined | { max: number; min: number } }): Motion

Parameters

options

{ duration: undefined | number; easing: undefined | ((x: number) => number); loop: undefined | boolean; range: undefined | { max: number; min: number } }

{}

Options

options.duration

undefined | number

Duration of the interpolation

options.easing

undefined | Function

options.loop

undefined | boolean

Whether to loop interpolation on finish

options.range

undefined | Object

Range of the interpolation

Properties

activated

>=4.0.0
readonly
activated

boolean

Whether the interpolation is in active state.

duration

>=4.0.0
duration

number

Duration of the interpolation

easing

>=4.0.0
easing

((x: number) => number)

Easing function of the interpolation

end

>=4.0.0
readonly
end

number

End(to) value of interpolation

loop

>=4.0.0
loop

boolean

Whether to loop interpolation on finish

progress

>=4.0.0
readonly
progress

number

Interpolation progress value (0 ~ 1)

range

>=4.0.0
readonly
range

Range

Range of the interpolation

start

>=4.0.0
readonly
start

number

Start(from) value of interpolation

val

>=4.0.0
readonly
val

number

Current interpolated value

Methods

add

add

void

add(delta: number): void

Add delta to start & end and current value.

Parameters

delta

number

Delta value to add

reset

>=4.0.0
reset

void

reset(defaultVal: number): void

Set start, end to the given value and set progress to 0.

Parameters

defaultVal

number

Value to reset

setNewEndByDelta

setNewEndByDelta

void

setNewEndByDelta(delta: number): void

Set current value to start, and end to current value + delta, then reset progress to 0.

Parameters

delta

number

Delta value to add

setRange

setRange

void

setRange(min: number, max: number): void

Set new range of the interpolation.

Parameters

min

number

New minimum range

max

number

New maximum range

update

>=4.0.0
update

number

update(deltaTime: number): number

Update motion and progress it by given deltaTime

Parameters

deltaTime

number

number of milisec to update motion

Returns

Difference(delta) of the value from the last update.