handleScreenBoundaries method

void handleScreenBoundaries(
  1. Size bounds
)

Implementation

void handleScreenBoundaries(Size bounds) {
  double dx = velocity.dx;
  double dy = velocity.dy;
  double defDx = defaultVelocity.dx;
  double defDy = defaultVelocity.dy;
  bool changed = false;

  if (position.dx < 0 || position.dx > bounds.width) {
    dx = -dx;
    defDx = -defDx;
    changed = true;
  }
  if (position.dy < 0 || position.dy > bounds.height) {
    dy = -dy;
    defDy = -defDy;
    changed = true;
  }

  if (changed) {
    velocity = Offset(dx, dy);
    defaultVelocity = Offset(defDx, defDy);
  }
}