openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
749 stars 362 forks source link

Make async assets to be available as sync assets if they are cached. #1755

Closed T1mL3arn closed 5 months ago

T1mL3arn commented 5 months ago

On html I get this

ERROR: IMAGE asset "asset_name.png" exists, but only asynchronously

Flixel always(probably) uses sync methods to retrieve assets (e.g. getText(), getSound()), making it impossible to use async assets on html5.

Dimensionscape commented 5 months ago

Retrieval of assets on html5 are inherently asynchronous only regardless of the overlaying technology such as openfl or flixel.

The one exception to this is embedding asset data directly into javascript via text-encoding such as base64.

player-03 commented 5 months ago

From the title it sounds like you want to do the following:

  1. Load asynchronously one time, and store the data in the cache.
  2. Use functions like getText() and getSound() to synchronously retrieve the data from cache.

I have good news and bad news on that front. The good news is that most of the functions already work that way. Sounds, images, and fonts are all cached, and the cache supersedes the "exists but only asynchronously" error. The bad news is that text is not cached on any target, and this was a deliberate decision way back when, so probably won't be changed.

In any case, Dimensionscape is right: there's no way around loading asynchronously at least once.

Dimensionscape commented 5 months ago

Just a note: getting a resource from the cache is still asynchronous even though it is much faster due being local.

I went ahead and closed this issue. If you're having a specific problem with Flixel, be sure to draft an issue there.

T1mL3arn commented 5 months ago

Trying to make a minimal repro I found the issue is on Flixel side.

T1mL3arn commented 5 months ago

@player-03

The bad news is that text is not cached on any target, and this was a deliberate decision way back when, so probably won't be changed.

Here you considered you can add text/binary cache.