setAnimationByName method

TrackEntry setAnimationByName(
  1. int trackIndex,
  2. String animationName,
  3. bool loop
)

Sets the current animation for a track, discarding any queued animations. @param loop If true, the animation will repeat. If false, it will not, instead its last frame is applied if played beyond its duration. In either case TrackEntry.TrackEnd determines when the track is cleared. @return A track entry to allow further customization of animation playback. References to the track entry must not be kept after AnimationState.Dispose.

Implementation

TrackEntry setAnimationByName(int trackIndex, String animationName, bool loop) {
  final animation = animationName.toNativeUtf8(allocator: _allocator);
  final entry =
      _bindings.spine_animation_state_set_animation_by_name(_state, trackIndex, animation.cast(), loop ? -1 : 0);
  _allocator.free(animation);
  if (entry.address == nullptr.address) throw Exception("Couldn't set animation $animationName");
  return TrackEntry._(entry, this);
}