flutter_gen
                                
                                
                                
                                    flutter_gen copied to clipboard
                            
                            
                            
                        Flame integration
FlutterGen is wonderfull, but I do not know how to use it with Flame. Flame already assumes that images are in assets/images/. When loading an image image.load('filename.png') is used without the path. FlutterGen generates the whole path. I guess I could always remove assets/images/ from the string before using it, but it does not feel right. Flame also has assets/audio/. Will there be support for audio, too, sometime in the future?
Thanks to you I finally understood about Flame. I'll develop the Flame integration again.
@markohrastovec Just update the prefix like this.
// If your assets directory structure is like this.
/**
└── images
    └─── dir_name
        └── image_name.png
*/
// world
class MyWorld extends World with HasGameReference<MyGame> {
  @override
  Future<void> onLoad() async {
    // Here is the point.
    game.images.prefix = '';
    await game.images
        .loadAll(Assets.images.dirName.values.map((v) => v.keyName).toList());
    add(MyComponent());
  }
}
// component
class MyComponent extends SpriteComponent with HasGameReference<MyGame> {
  @override
  Future<void> onLoad() async {
    final image =
        game.images.fromCache(Assets.images.dirName.imageName.keyName);
    sprite = Sprite(image);
  }
}
                                    
                                    
                                    
                                
It seems no extra work is required in the package. The above comment already suggested a valid workaround.