【问题标题】:Undefined class 'TapDownInfo' in flutter/flame颤动/火焰中未定义的类“TapDownInfo”
【发布时间】:2021-05-04 09:22:16
【问题描述】:

flutter 的游戏/动画包 "flame" 有几个教程,其中第二个 (link) 由于 Undefined class 'TapDownInfo' 而无法编译。

我需要包含哪些内容,或者与 Flutter SDK 的早期版本有关? (目前sdk: ">=2.12.0 <3.0.0"flame: ^1.0.0-rc9

@override
void onTapDown(TapDownInfo event) {
  final buttonArea = buttonPosition & buttonSize;
  isPressed = buttonArea.contains(event.eventPosition.game.toOffset());
}

【问题讨论】:

    标签: flutter dart flame


    【解决方案1】:

    rc9 不存在该教程,如果您想要特定于某个版本的教程,您必须在 git 中查看该标签。例如: https://github.com/flame-engine/flame/tree/1.0.0-rc9/tutorials

    如果您想运行该教程,也可以克隆火焰存储库,或者依赖main 分支而不是rc9

    我们很可能会在今天或明天发布rc10,其中将包含该教程。

    您可以通过以下方式在您的pubspec.yaml 中依赖main

    dependencies:
      flame:
        git:
          url: https://github.com/flame-engine/flame.git
          path: packages/flame
          ref: main
    

    编辑:1.0.0-rc10 现已发布,因此您可以直接使用该版本的教程。

    【讨论】:

      【解决方案2】:

      对于1.0.0-rc10。 (我同意,在真正发布之前,有时很难找到好的文档(对于最新版本)。

      对于您的问题,这取决于您是否谈论您的主要游戏组件(extends BaseGame)以及您是否拥有with HasTapableComponents

      如果它是你的mainGame extends BaseGame with HasTapableComponents,它应该像这样被覆盖:

        @override
        bool onTapDown(int pointerId, TapDownDetails details) {
          super.onTapDown(pointerId, details);
          // Your code
          return true;
        }
      

      在其他子组件上是这样的:ExitButton extends PositionComponent with Tapable,如果没有pointerId,它看起来应该是一样的。

        @override
        bool onTapDown(TapDownDetails details) {
          super.onTapDown(details);
          // Your code
          return true;
        }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-25
        • 1970-01-01
        • 2021-03-30
        相关资源
        最近更新 更多