flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.28k stars 912 forks source link

feat: use the `AssetBundle` API to provide more familiar ways to load assets #3252

Open wolfenrain opened 3 months ago

wolfenrain commented 3 months ago

What could be improved

The way Flame handles assets is currently a bit ambiguous, images go through the Images class while other type of files (for instance tiled maps) have their own parsers in the bridge packages. This is also not the common way most Flutter developers are used to handling assets.

Why should this be improved

Flutter already provides a way to load assets, that we internally already use, namely the AssetBundle class. This class however still does not provide direct ways to load asset types like images, tiled map and others. But we can extend it, and it even has a CachedAssetBundle variant that does caching for us.

My suggestion is to create a FlameAssetBundle that can load different kinds of types like images and tiled map (through extensions provided in the bridge package). This allows us to make it more user-friendly, flutter developers know about rootBundle and AssetBundle and allows our bridge packages to make loading assets for their implementation much easier.

Risks

None to my knowledge, the Images can still exist for backwards compatibilty but under the hood it can use the Flame bundle system.

More information

I already have been using this idea for my own games and would love to provide my implementation as a PR if we all agree on this idea.

Other

wolfenrain commented 3 months ago

For the implementation I am planning on doing 3 PRs:

spydon commented 1 month ago

@wolfenrain you haven't forgotten this one right? :wink: