如何在 Flame Flutter 中将 TapDetector 和 HasTappable mixin 添加到游戏 class 中?

How to add both TapDetector and HasTappable mixin to the game class in Flame Flutter?

我想将 Tap 功能添加到游戏 class 本身和组件中,但不能同时将 TapDetectorHasTappable mixin 添加到游戏 class 中!应该采取什么方法?

如果你的 FlameGame class 上有 HasTappables mixin,你不需要 TapDetector,你可以覆盖:

  void onTapCancel(int pointerId);
  void onTapDown(int pointerId, TapDownInfo info);
  void onTapUp(int pointerId, TapUpInfo info);

因为它们存在于 HasTappables

并且记得在覆盖它们时调用 super(你的 IDE 也会提醒你)。