play method
Method used to play specific default animation
Implementation
void play(SimpleAnimationEnum animation) {
if (_currentType == animation) return;
isFlipHorizontally = false;
isFlipVertically = false;
_currentType = animation;
if (!runToTheEndFastAnimation) {
_fastAnimation = null;
}
switch (animation) {
case SimpleAnimationEnum.idleLeft:
_idleLeft();
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) {
isFlipVertically = true;
_current = idleUp;
}
break;
case SimpleAnimationEnum.idleUpLeft:
if (idleUpLeft != null) {
_current = idleUpLeft;
} else if (idleUpRight != null) {
_current = idleUpRight;
isFlipHorizontally = true;
} else {
_idleLeft();
}
break;
case SimpleAnimationEnum.idleUpRight:
if (idleUpRight != null) {
_current = idleUpRight;
} else {
_current = idleRight;
}
break;
case SimpleAnimationEnum.idleDownLeft:
if (idleDownLeft != null) {
_current = idleDownLeft;
} else if (idleDownRight != null) {
_current = idleDownRight;
isFlipHorizontally = true;
} else {
_idleLeft();
}
break;
case SimpleAnimationEnum.idleDownRight:
if (idleDownRight != null) {
_current = idleDownRight;
} else {
_current = idleRight;
}
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:
_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) {
isFlipVertically = true;
_current = runUp;
}
}
} else {
if (runDown != null) {
_current = runDown;
} else if (enabledFlipY && runUp != null) {
isFlipVertically = true;
_current = runUp;
}
}
changeLastAnimation(SimpleAnimationEnum.runDown);
} else {
if (runDown != null) {
_current = runDown;
} else if (enabledFlipY && runUp != null) {
isFlipVertically = true;
_current = runUp;
}
}
break;
case SimpleAnimationEnum.runLeft:
_runLeft();
break;
case SimpleAnimationEnum.runUpLeft:
if (runUpLeft != null) {
_current = runUpLeft;
changeLastAnimation(SimpleAnimationEnum.runUpLeft);
} else if (runUpRight != null) {
_current = runUpRight;
isFlipHorizontally = true;
changeLastAnimation(SimpleAnimationEnum.runUpLeft);
} else {
_runLeft();
}
break;
case SimpleAnimationEnum.runUpRight:
if (runUpRight != null) {
_current = runUpRight;
changeLastAnimation(SimpleAnimationEnum.runUpRight);
} else {
_runRight();
}
break;
case SimpleAnimationEnum.runDownLeft:
if (runDownLeft != null) {
_current = runDownLeft;
changeLastAnimation(SimpleAnimationEnum.runDownLeft);
} else if (runDownRight != null) {
_current = runDownRight;
isFlipHorizontally = true;
changeLastAnimation(SimpleAnimationEnum.runDownLeft);
} else {
_runLeft();
}
break;
case SimpleAnimationEnum.runDownRight:
if (runDownRight != null) {
_current = runDownRight;
changeLastAnimation(SimpleAnimationEnum.runDownRight);
} else {
_runRight();
}
break;
case SimpleAnimationEnum.custom:
break;
}
}