首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >flame版本检查中的onTapDown问题。15

flame版本检查中的onTapDown问题。15
EN

Stack Overflow用户
提问于 2021-11-03 15:57:13
回答 1查看 70关注 0票数 0

长话短说。我在扩展窗口小部件中使用火焰引擎。现在,我正在加载六个背景以及我的SpriteComponent类,在游戏中用HasTappableComponents扩展FlameGame。现在我想在这个SpriteComponent中添加一些交互,比如在没有点击的情况下进行点击或者切换动画。我不明白为什么它连‘点击’都不打印出来...

代码语言:javascript
复制
class FoxCharacter extends SpriteComponent with Tappable, HasGameRef  {

  String working = "like a charm";

  late SpriteAnimation animation;
  late SpriteAnimationComponent animationComponent2;

  Future<void> onLoad() async {
    super.onLoad();

    animation = await gameRef.loadSpriteAnimation(
      'fox.png',
      SpriteAnimationData.sequenced(
        amount: 8,
        textureSize: Vector2(64.0, 59.0),
        stepTime: 0.15,
      ),
    );

    animationComponent2 = SpriteAnimationComponent(
      animation: animation,
      size: Vector2(200.0, 200.0),
      position:Vector2(gameRef.size.x / 2 - 50, gameRef.size.y - 215),

    );

    add(animationComponent2);
    print(working);
  }

  @override
  bool onTapDown(TapDownInfo event) {
    print("tap down");
    return true;
  }

}

我试着把final改成late,以及其他一些无聊的想法,但都没有结果。如何向此FoxCharacter添加交互组件?有没有可能它不能在SpriteComponent中使用,而只能在PositionComponent中使用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-03 22:31:19

这是因为您的SpriteComponent (FoxCharacter)没有大小或hitbox,所以事件系统不知道如何检查它是否应该传递事件。它确实有一个子对象(animationComponent2),这是您可以在屏幕上看到的。

在我看来,您需要使用SpriteAnimationGroupComponent并设置该组件的位置和大小,然后添加要在该组件中交换的所有不同动画。

当然,您可以只将相同的sizeposition设置为SpriteComponent,而不是将它们传递给animationComponent2,但我认为在该部分完成后,您还会遇到其他问题。

您可以查看SpriteAnimationGroupComponent here的文档

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69827991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档