showDamage method

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

Add in the game a text with animation representing damage received

Implementation

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