VeryGoodOpenSource / very_good_cli

A Very Good Command-Line Interface for Dart created by Very Good Ventures 🦄

Home Page:http://cli.vgv.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fix: resolve image caching issue on flame_game template

BBarisKilic opened this issue · comments

Description
There is a bug on the generated flame_game template. The cached images are not accessible from the FlameGame, therefore they are not "actually" cached and causing a runtime error.

Steps To Reproduce

  1. Go to lib > game > entities > unicorn > unicorn.dart.
  2. The onLoad method of the Unicorn class is currently like this:
 @override
  Future<void> onLoad() async {
    final animation = await gameRef.loadSpriteAnimation(
      Assets.images.unicornAnimation.path,
      SpriteAnimationData.sequenced(
        amount: 16,
        stepTime: 0.1,
        textureSize: Vector2.all(32),
        loop: false,
      ),
    );

    await add(
      _animationComponent = SpriteAnimationComponent(
        animation: animation,
        size: size,
      ),
    );

    resetAnimation();
  }
  1. Modify the onLoad method as follows to produce the issue in an easy way:
  @override
  Future<void> onLoad() async {
    final animation = SpriteAnimation.fromFrameData(
      gameRef.images.fromCache(Assets.images.unicornAnimation.path),
      SpriteAnimationData.sequenced(
        amount: 16,
        stepTime: 0.1,
        textureSize: Vector2.all(32),
        loop: false,
      ),
    );

    await add(
      _animationComponent = SpriteAnimationComponent(
        animation: animation,
        size: size,
      ),
    );

    resetAnimation();
  }
  1. Run the project and the error will be thrown as soon as the Start button gets clicked.

Expected Behavior
I would expect not to receive a runtime error that claims the image is not cached even though it is cached.

Additional Context
Error message: "Tried to access an image \"assets/images/unicorn_animation.png\" that does not exist in the cache. Make sure to load() an image before accessing it"