initialize method

void initialize(
  1. PlayerControllerListener controller,
  2. Viewport viewPort
)

Implementation

void initialize(
  PlayerControllerListener controller,
  camera.Viewport viewPort,
) {
  if (_screenSize == viewPort.virtualSize) return;
  _viewPort = viewPort;
  _screenSize = viewPort.virtualSize.clone();
  _controller = controller;
  final radius = size / 2;

  final screenRect = Rect.fromLTRB(
    margin.left + radius,
    margin.top + radius,
    _screenSize.x - margin.right - radius,
    _screenSize.y - margin.bottom - radius,
  );

  Offset osBackground = alignment.withinRect(screenRect);

  _backgroundRect = Rect.fromCircle(
    center: osBackground,
    radius: radius,
  );

  Offset osKnob = Offset(
    _backgroundRect!.center.dx,
    _backgroundRect!.center.dy,
  );

  _knobRect = Rect.fromCircle(
    center: osKnob,
    radius: size / 4,
  );

  _dragPosition = _knobRect!.center;
}