play method

void play(
  1. SimpleAnimationEnum animation
)

Method used to play specific default animation

Implementation

void play(SimpleAnimationEnum animation) {
  if (_currentType == animation) return;
  isFlipHorizontally = false;
  isFlipVertically = false;

  _currentType = animation;
  _currentKeyCustom = null;
  if (!runToTheEndFastAnimation) {
    _fastAnimation?.onFinish?.call();
    _fastAnimation = null;
  }
  switch (animation) {
    case SimpleAnimationEnum.idleLeft:
      _idleLeft();
      break;
    case SimpleAnimationEnum.idleRight:
      _current.animation = _idleRightAnim;
      break;
    case SimpleAnimationEnum.idleUp:
      if (_idleUpAnim != null) _current.animation = _idleUpAnim;
      break;
    case SimpleAnimationEnum.idleDown:
      if (_idleDownAnim != null) {
        _current.animation = _idleDownAnim;
      } else if (enabledFlipY && _idleUpAnim != null) {
        isFlipVertically = true;
        _current.animation = _idleUpAnim;
      }
      break;
    case SimpleAnimationEnum.idleUpLeft:
      if (_idleUpLeftAnim != null) {
        _current.animation = _idleUpLeftAnim;
      } else if (_idleUpRightAnim != null) {
        _current.animation = _idleUpRightAnim;
        isFlipHorizontally = true;
      } else {
        _idleLeft();
      }
      break;
    case SimpleAnimationEnum.idleUpRight:
      if (_idleUpRightAnim != null) {
        _current.animation = _idleUpRightAnim;
      } else {
        _current.animation = _idleRightAnim;
      }
      break;
    case SimpleAnimationEnum.idleDownLeft:
      if (_idleDownLeftAnim != null) {
        _current.animation = _idleDownLeftAnim;
      } else if (_idleDownRightAnim != null) {
        _current.animation = _idleDownRightAnim;
        isFlipHorizontally = true;
      } else {
        _idleLeft();
      }
      break;
    case SimpleAnimationEnum.idleDownRight:
      if (_idleDownRightAnim != null) {
        _current.animation = _idleDownRightAnim;
      } else {
        _current.animation = _idleRightAnim;
      }
      break;
    case SimpleAnimationEnum.runUp:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runRight ||
            lastPlayedAnimation == SimpleAnimationEnum.runLeft) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runUpRight) {
            _current.animation = _runUpRightAnim;
          } else if (beforeLastPlayedAnimation ==
              SimpleAnimationEnum.runUpLeft) {
            _current.animation = _runUpLeftAnim;
          } else if (_runUpAnim != null) {
            _current.animation = _runUpAnim;
          }
        } else if (_runUpAnim != null) {
          _current.animation = _runUpAnim;
        }
        _changeLastAnimation(SimpleAnimationEnum.runUp);
      } else if (_runUpAnim != null) {
        _current.animation = _runUpAnim;
      }
      break;
    case SimpleAnimationEnum.runRight:
      _runRight();
      break;
    case SimpleAnimationEnum.runDown:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runRight ||
            lastPlayedAnimation == SimpleAnimationEnum.runLeft) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runDownRight) {
            _current.animation = _runDownRightAnim;
          } else if (beforeLastPlayedAnimation ==
              SimpleAnimationEnum.runDownLeft) {
            _current.animation = _runDownLeftAnim;
          } else {
            if (_runDownAnim != null) {
              _current.animation = _runDownAnim;
            } else if (enabledFlipY && _runUpAnim != null) {
              isFlipVertically = true;
              _current.animation = _runUpAnim;
            }
          }
        } else {
          if (_runDownAnim != null) {
            _current.animation = _runDownAnim;
          } else if (enabledFlipY && _runUpAnim != null) {
            isFlipVertically = true;
            _current.animation = _runUpAnim;
          }
        }
        _changeLastAnimation(SimpleAnimationEnum.runDown);
      } else {
        if (_runDownAnim != null) {
          _current.animation = _runDownAnim;
        } else if (enabledFlipY && _runUpAnim != null) {
          isFlipVertically = true;
          _current.animation = _runUpAnim;
        }
      }
      break;
    case SimpleAnimationEnum.runLeft:
      _runLeft();
      break;
    case SimpleAnimationEnum.runUpLeft:
      if (_runUpLeftAnim != null) {
        _current.animation = _runUpLeftAnim;
        _changeLastAnimation(SimpleAnimationEnum.runUpLeft);
      } else if (_runUpRightAnim != null) {
        _current.animation = _runUpRightAnim;
        isFlipHorizontally = true;
        _changeLastAnimation(SimpleAnimationEnum.runUpLeft);
      } else {
        _runLeft();
      }
      break;
    case SimpleAnimationEnum.runUpRight:
      if (_runUpRightAnim != null) {
        _current.animation = _runUpRightAnim;
        _changeLastAnimation(SimpleAnimationEnum.runUpRight);
      } else {
        _runRight();
      }
      break;
    case SimpleAnimationEnum.runDownLeft:
      if (_runDownLeftAnim != null) {
        _current.animation = _runDownLeftAnim;
        _changeLastAnimation(SimpleAnimationEnum.runDownLeft);
      } else if (_runDownRightAnim != null) {
        _current.animation = _runDownRightAnim;
        isFlipHorizontally = true;
        _changeLastAnimation(SimpleAnimationEnum.runDownLeft);
      } else {
        _runLeft();
      }
      break;
    case SimpleAnimationEnum.runDownRight:
      if (_runDownRightAnim != null) {
        _current.animation = _runDownRightAnim;
        _changeLastAnimation(SimpleAnimationEnum.runDownRight);
      } else {
        _runRight();
      }
      break;
    case SimpleAnimationEnum.custom:
      break;
  }
}