# ThorVG: Animation

Animation
ThorVG

The Animation class enables manipulation of animatable images. More...

## Public Member Functions

Result | frame (float no) noexcept
| Specifies the current frame in the animation. More...
Picture * | picture () const noexcept
| Retrieves a picture instance associated with this animation instance. More...
float | curFrame () const noexcept
| Retrieves the current frame number of the animation. More...
float | totalFrame () const noexcept
| Retrieves the total number of frames in the animation. More...
float | duration () const noexcept
| Retrieves the duration of the animation in seconds. More...
Result | segment (float begin, float end) noexcept
| Specifies the playback segment of the animation. More...
Result | segment (float *begin, float *end=nullptr) noexcept
| Gets the current segment. More...

## Static Public Member Functions

static std::unique_ptr< Animation > | gen () noexcept
| Creates a new Animation object. More...

## Detailed Description

The Animation class enables manipulation of animatable images.

This class supports the display and control of animation frames.

Since
  0.13

## Member Function Documentation

## curFrame()

float curFrame | ( |  | ) | const

noexcept

Retrieves the current frame number of the animation.

Returns
  The current frame number of the animation, between 0 and totalFrame() - 1.

Note
  If the Picture is not properly configured, this function will return 0.

See also
  Animation::frame(float no)
  Animation::totalFrame()

## duration()

float duration | ( |  | ) | const

noexcept

Retrieves the duration of the animation in seconds.

Returns
  The duration of the animation in seconds.

Note
  If the Picture is not properly configured, this function will return 0.

## frame()

Result frame | ( | float | no | ) |

noexcept

Specifies the current frame in the animation.

Parameters

  [in] | no | The index of the animation frame to be displayed. The index should be less than the totalFrame().

Return values

  Result::InsufficientCondition | if the given `no` is the same as the current frame value.
  Result::NonSupport | The current Picture data does not support animations.

Note
  For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value is less than 0.001. In such cases, it returns `Result::InsufficientCondition`. Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.

See also
  totalFrame()

## gen()

static std::unique_ptr<Animation> gen | ( |  | ) |

staticnoexcept

Creates a new Animation object.

Returns
  A new Animation object.

## picture()

Picture* picture | ( |  | ) | const

noexcept

Retrieves a picture instance associated with this animation instance.

This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames with this Animation instance.

Returns
  A picture instance that is tied to this animation.

Warning
  The picture instance is owned by Animation. It should not be deleted manually.

## segment() [1/2]

Result segment | ( | float * | begin,
|  | float * | end = `nullptr`
| ) |  |

noexcept

Gets the current segment.

Parameters

  [out] | begin | segment start.
  [out] | end | segment end.

Return values

  Result::InsufficientCondition | In case the animation is not loaded.
  Result::NonSupport | When it's not animatable.

Note
  Experimental API

## segment() [2/2]

Result segment | ( | float | begin,
|  | float | end
| ) |  |

noexcept

Specifies the playback segment of the animation.

The set segment is designated as the play area of the animation. This is useful for playing a specific segment within the entire animation. After setting, the number of animation frames and the playback time are calculated by mapping the playback segment as the entire range.

Parameters

  [in] | begin | segment start.
  [in] | end | segment end.

Return values

  Result::InsufficientCondition | In case the animation is not loaded.
  Result::NonSupport | When it's not animatable.

Note
  Animation allows a range from 0.0 to 1.0. `end` should not be higher than `begin`.
  If a marker has been specified, its range will be disregarded.

See also
  LottieAnimation::segment(const char* marker)

Note
  Experimental API

## totalFrame()

float totalFrame | ( |  | ) | const

noexcept

Retrieves the total number of frames in the animation.

Returns
  The total number of frames in the animation.

Note
  Frame numbering starts from 0.
  If the Picture is not properly configured, this function will return 0.