Search code examples
flutterdartflame

Adding a name tag to a component when selected in flutter flame


How can I have text appear on top of a component when it is selected? I am trying to select a component and have the name of the component appear at the top of it. And help is appreciated as I am quite lost


Solution

  • Add TappableComponent to your component and HasTappableComponents to the game to start with.

    Then add a TextComponent as a child of your component by overriding onTapDown inside of your component, like this:

    final text = TextComponent(text: 'text');
    void onTapDown(TapDownEvent event) {
      add(text);
    }