【问题标题】:The argument type 'List<Future<Sprite>>' can't be assigned to the parameter type 'List<Sprite>'参数类型“List<Future<Sprite>>”不能分配给参数类型“List<Sprite>”
【发布时间】:2021-07-06 06:58:29
【问题描述】:
class MyGame extends BaseGame with HasTapableComponents {
  SpriteAnimationComponent girl = SpriteAnimationComponent();

  MyGame();
  @override
  Future<void> onLoad() async {
    final sprites = [0, 1, 2,3,4,5,6,7,8,9]
      .map((i) async => await Sprite.load('Attack__00$i.png'))
      .toList();
    girl = SpriteAnimationComponent(
      animation: SpriteAnimation.spriteList(sprites, stepTime: 0.01),
      size: Vector2.all(100) 
    );
    add(girl);
    print(size);
  }
}

SpriteAnimationComponent 的实现按照 Flutter Flame 的 github 文档,animation: SpriteAnimation.spriteList(sprites, ...)。我注意到这里的问题是sprites 是一个未来的精灵列表,而 spriteList 需要一个精灵列表。这是文档中的问题,还是我在某个地方出错了?

【问题讨论】:

    标签: flutter asynchronous flame


    【解决方案1】:

    您必须等待未来精灵列表实现,如下所示:

    final sprites = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
          .map((i) => Sprite.load('Attack__00$i.png'));
    final animation = SpriteAnimation.spriteList(
      await Future.wait(sprites),
      stepTime: 0.01,
    );
    girl = SpriteAnimationComponent(
      animation: animation,
      size: Vector2.all(100) 
    );
    add(girl);
    

    编辑:我可以在文档中看到它是错误的,我会更新它们。

    【讨论】:

      猜你喜欢
      • 2020-03-22
      • 2021-07-10
      • 2021-07-20
      • 2021-07-04
      • 2021-12-10
      • 2021-10-24
      • 2022-11-05
      • 2021-11-05
      • 2020-08-26
      相关资源
      最近更新 更多