render method

  1. @override
void render(
  1. Canvas canvas
)
override

Implementation

@override
void render(Canvas canvas) {
  super.render(canvas);
  if (!_containsColor()) return;
  Vector2 size = gameRef.size;
  canvas.saveLayer(Offset.zero & Size(size.x, size.y), Paint());
  canvas.drawColor(color!, BlendMode.dstATop);
  _visibleLight.forEach((light) {
    final config = light.lightingConfig;
    if (config == null) return;
    final sigma = _convertRadiusToSigma(config.blurBorder);
    config.update(_dtUpdate);
    canvas.save();

    canvas.translate(size.x / 2, size.y / 2);
    canvas.scale(gameRef.camera.config.zoom);
    canvas.translate(
      -(gameRef.camera.position.dx),
      -(gameRef.camera.position.dy),
    );

    canvas.drawCircle(
      Offset(
        light.position.center.dx,
        light.position.center.dy,
      ),
      config.radius *
          (config.withPulse
              ? (1 - config.valuePulse * config.pulseVariation)
              : 1),
      _paintFocus
        ..maskFilter = MaskFilter.blur(
          BlurStyle.normal,
          sigma,
        ),
    );

    _paintLighting
      ..color = config.color
      ..maskFilter = MaskFilter.blur(
        BlurStyle.normal,
        sigma,
      );
    canvas.drawCircle(
      light.position.center,
      config.radius *
          (config.withPulse
              ? (1 - config.valuePulse * config.pulseVariation)
              : 1),
      _paintLighting,
    );

    canvas.restore();
  });
  canvas.restore();
}