如何在 Flutter Flame 游戏引擎启动时停止精灵动画

How to stop sprite animation at start in Flutter Flame game engine

我要渲染这张卡片,第一次加载时,动画开始一次。我想要的是默认没有动画发生。有谁知道如何做到这一点?


    class Card extends AnimationComponent {
      Card(width, height)
          : super.sequenced(width, height, 'card.png', 5,
                textureWidth: 144.0, textureHeight: 220.0, loop: false);

    }


    class GameScreen extends BaseGame {
      GameScreen({@required this.size}) {
        add(Card(0,0));
      }
    }

根据source code, you'll able to use Animation来控制边框。

简单来说,就是不调用update继续渲染,帧索引不会更新。

  void update(double dt) {
    clock += dt;
    elapsed += dt;
    if (isSingleFrame) {
      return;
    }
    if (!loop && isLastFrame) {
      onCompleteAnimation?.call();
      return;
    }
    while (clock > currentFrame.stepTime) {
      if (!isLastFrame) {
        clock -= currentFrame.stepTime;
        currentIndex++;
      } else if (loop) {
        clock -= currentFrame.stepTime;
        currentIndex = 0;
      } else {
        break;
      }
    }
  }

所以你可以重写 update 方法来控制精灵动画。