Flutter 如何在带有颤振/火焰的游戏中检测长按

Flutter 如何在带有颤振/火焰的游戏中检测长按,flutter,flame,Flutter,Flame,我有一个矩形出现在游戏中,我能够检测到这样的点击 主要是飞镖 TapGestureRecognizer tapper = TapGestureRecognizer(); tapper.onTapDown = game.onTapDown; flameUtil.addGestureRecognizer(tapper); 在游戏控制器中 void onTapDown(TapDownDetails d) { if (mainMenu.tutorialBtnRect.contains(d.glob

我有一个矩形出现在游戏中,我能够检测到这样的点击

主要是飞镖

TapGestureRecognizer tapper = TapGestureRecognizer();
tapper.onTapDown = game.onTapDown;
flameUtil.addGestureRecognizer(tapper);
在游戏控制器中

void onTapDown(TapDownDetails d) {
  if (mainMenu.tutorialBtnRect.contains(d.globalPosition)) {
   mainMenu.tutorialTapped();
  }
}
我似乎无法让它与任何长按手势一起工作 关于PrimaryButton和速度,我无法设置

请帮忙


谢谢

不用手势识别器,只需直接在游戏中使用即可

class MyGame extends BaseGame with LongPressDetector {

  MyGame();

  @override
  void onLongPressEnd(LongPressEndDetails details) {
    if (mainMenu.tutorialBtnRect.contains(details.globalPosition)) {
      mainMenu.tutorialTapped();
    }
  }
}

不使用手势识别器而直接在游戏中实现它更容易

class MyGame extends BaseGame with LongPressDetector {

  MyGame();

  @override
  void onLongPressEnd(LongPressEndDetails details) {
    if (mainMenu.tutorialBtnRect.contains(details.globalPosition)) {
      mainMenu.tutorialTapped();
    }
  }
}

您可以在您的游戏类中使用“LongPressDetector”mixin,它从flame扩展了“game”。您可以在您的游戏类中使用“LongPressDetector”mixin,它从flame扩展了“game”。