flame

Set world backgroundcolor


How can you set the background color?

I tried setting this in onLoad:

world.color.setRGB(0,0,255);

I also tried adding a component, but I maybe there is a better way:

class Background extends PositionComponent with HasGameRef {
  @override
  int priority = -1;

  late Paint white;
  late final Rect hugeRect;

  Background() : super(size: Vector2.all(100000));

  @override
  Future<void> onLoad() async {
    white = BasicPalette.blue.paint();
    hugeRect = size.toRect();
  }

  @override
  void render(Canvas c) {
    c.drawRect(hugeRect, white);
  }
}

Solution

  •   @override
      Color backgroundColor() => const Color(0xFFeeeeee);