Home > Net >  Adding a name tag to a component when selected in flutter flame
Adding a name tag to a component when selected in flutter flame

Time:10-21

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

CodePudding user response:

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);
}
  • Related