showDamage method

void showDamage(
  1. double damage, {
  2. TextStyle? config,
  3. double initVelocityTop = -5,
  4. double gravity = 0.5,
  5. double maxDownSize = 20,
  6. DirectionTextDamage direction = DirectionTextDamage.RANDOM,
  7. bool onlyUp = false,
})

Add in the game a text with animation representing damage received

Implementation

void showDamage(
  double damage, {
  TextStyle? config,
  double initVelocityTop = -5,
  double gravity = 0.5,
  double maxDownSize = 20,
  DirectionTextDamage direction = DirectionTextDamage.RANDOM,
  bool onlyUp = false,
}) {
  if (!hasGameRef) return;
  gameRef.add(
    TextDamageComponent(
      damage.toInt().toString(),
      Vector2(
        center.x,
        y,
      ),
      config: config ??
          const TextStyle(
            fontSize: 14,
            color: Color(0xFFFFFFFF),
          ),
      initVelocityTop: initVelocityTop,
      gravity: gravity,
      direction: direction,
      onlyUp: onlyUp,
      maxDownSize: maxDownSize,
    ),
  );
}