【问题标题】:How to detect a Long press in a game with flutter/flame如何在颤动/火焰的游戏中检测长按
【发布时间】:2020-05-08 17:16:07
【问题描述】:

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

在 main.dart 中

TapGestureRecognizer tapper = TapGestureRecognizer();
tapper.onTapDown = game.onTapDown;
flameUtil.addGestureRecognizer(tapper);

在 game-controller.dart 中

void onTapDown(TapDownDetails d) {
  if (mainMenu.tutorialBtnRect.contains(d.globalPosition)) {
   mainMenu.tutorialTapped();
  }
}

我似乎无法让它与任何 LongPressGestures 一起使用 关于 PrimaryButton 和速度的一些东西我无法设置

请帮忙

谢谢

【问题讨论】:

  • 你可以在你的游戏类中使用'LongPressDetector' mixin,它从flame扩展'Game'。

标签: flutter flame


【解决方案1】:

不使用 GestureRecognizers 并直接在您的游戏中实现它会更容易。

class MyGame extends BaseGame with LongPressDetector {

  MyGame();

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2021-01-15
    • 2022-10-08
    相关资源
    最近更新 更多