play method

void play(
  1. SimpleAnimationEnum animation
)

Method used to play specific default animation

Implementation

void play(SimpleAnimationEnum animation) {
  _flipX = false;
  _flipY = false;
  _currentType = animation;
  if (!runToTheEndFastAnimation) {
    _fastAnimation = null;
  }
  switch (animation) {
    case SimpleAnimationEnum.idleLeft:
      if (idleLeft != null) {
        _current = idleLeft;
      } else if (enabledFlipX) {
        _flipX = true;
        _current = idleRight;
      }
      break;
    case SimpleAnimationEnum.idleRight:
      _current = idleRight;
      break;
    case SimpleAnimationEnum.idleUp:
      if (idleUp != null) _current = idleUp;
      break;
    case SimpleAnimationEnum.idleDown:
      if (idleDown != null) {
        _current = idleDown;
      } else if (enabledFlipY && idleUp != null) {
        _flipY = true;
        _current = idleUp;
      }
      break;
    case SimpleAnimationEnum.idleUpLeft:
      if (idleUpLeft != null) _current = idleUpLeft;
      break;
    case SimpleAnimationEnum.idleUpRight:
      if (idleUpRight != null) _current = idleUpRight;
      break;
    case SimpleAnimationEnum.idleDownLeft:
      if (idleDownLeft != null) _current = idleDownLeft;
      break;
    case SimpleAnimationEnum.idleDownRight:
      if (idleDownRight != null) _current = idleDownRight;
      break;
    case SimpleAnimationEnum.runUp:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runRight ||
            lastPlayedAnimation == SimpleAnimationEnum.runLeft) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runUpRight) {
            _current = runUpRight;
          } else if (beforeLastPlayedAnimation ==
              SimpleAnimationEnum.runUpLeft) {
            _current = runUpLeft;
          } else if (runUp != null) {
            _current = runUp;
          }
        } else if (runUp != null) {
          _current = runUp;
        }
        changeLastAnimation(SimpleAnimationEnum.runUp);
      } else if (runUp != null) {
        _current = runUp;
      }
      break;
    case SimpleAnimationEnum.runRight:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runUpRight ||
            lastPlayedAnimation == SimpleAnimationEnum.runDownRight) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runDown) {
            _current = runDownRight;
          } else if (beforeLastPlayedAnimation == SimpleAnimationEnum.runUp) {
            _current = runUpRight;
          } else {
            _current = runRight;
          }
        } else {
          _current = runRight;
        }
        changeLastAnimation(SimpleAnimationEnum.runRight);
      } else {
        _current = runRight;
      }
      break;
    case SimpleAnimationEnum.runDown:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runRight ||
            lastPlayedAnimation == SimpleAnimationEnum.runLeft) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runDownRight) {
            _current = runDownRight;
          } else if (beforeLastPlayedAnimation ==
              SimpleAnimationEnum.runDownLeft) {
            _current = runDownLeft;
          } else {
            if (runDown != null) {
              _current = runDown;
            } else if (enabledFlipY && runUp != null) {
              _flipY = true;
              _current = runUp;
            }
          }
        } else {
          if (runDown != null) {
            _current = runDown;
          } else if (enabledFlipY && runUp != null) {
            _flipY = true;
            _current = runUp;
          }
        }
        changeLastAnimation(SimpleAnimationEnum.runDown);
      } else {
        if (runDown != null) {
          _current = runDown;
        } else if (enabledFlipY && runUp != null) {
          _flipY = true;
          _current = runUp;
        }
      }
      break;
    case SimpleAnimationEnum.runLeft:
      if (eightDirection) {
        if (lastPlayedAnimation == SimpleAnimationEnum.runUpLeft ||
            lastPlayedAnimation == SimpleAnimationEnum.runDownLeft) {
          if (beforeLastPlayedAnimation == SimpleAnimationEnum.runDown) {
            _current = runDownLeft;
          } else if (beforeLastPlayedAnimation == SimpleAnimationEnum.runUp) {
            _current = runUpLeft;
          } else {
            if (runLeft != null) {
              _current = runLeft;
            } else if (enabledFlipX) {
              _flipX = true;
              _current = runRight;
            }
          }
        } else {
          if (runLeft != null) {
            _current = runLeft;
          } else if (enabledFlipX) {
            _flipX = true;
            _current = runRight;
          }
        }
        changeLastAnimation(SimpleAnimationEnum.runLeft);
      } else {
        if (runLeft != null) {
          _current = runLeft;
        } else if (enabledFlipX) {
          _flipX = true;
          _current = runRight;
        }
      }
      break;
    case SimpleAnimationEnum.runUpLeft:
      if (runUpLeft != null) {
        _current = runUpLeft;
        changeLastAnimation(SimpleAnimationEnum.runUpLeft);
      }
      break;
    case SimpleAnimationEnum.runUpRight:
      if (runUpRight != null) {
        _current = runUpRight;
        changeLastAnimation(SimpleAnimationEnum.runUpRight);
      }
      break;
    case SimpleAnimationEnum.runDownLeft:
      if (runDownLeft != null) {
        _current = runDownLeft;
        changeLastAnimation(SimpleAnimationEnum.runDownLeft);
      }
      break;
    case SimpleAnimationEnum.runDownRight:
      if (runDownRight != null) {
        _current = runDownRight;
        changeLastAnimation(SimpleAnimationEnum.runDownRight);
      }
      break;
    case SimpleAnimationEnum.custom:
      break;
  }
}