onLoad method

  1. @override
Future<void> onLoad()

Loads the button's components (background and text).

Implementation

@override
Future<void> onLoad() async {
  if (_label != null && _label!.isNotEmpty) {
    _text = TextComponent(
      text: _label,
      anchor: Anchor.center,
      position: size / 2,
      textRenderer: TextPaint(
        style: TextStyle(color: textColor, fontSize: 10),
      ),
    );
    add(_text!);
  } else if (sprite != null) {
    _icon = SpriteComponent(
      sprite: sprite!,
      anchor: Anchor.center,
      position: size / 2,
    );
    add(_icon!);
  }
}