Jump to content

Caching resources using PIXI.Loader.pre


codingchili
 Share

Recommended Posts

Hello,

I'm using pixi 5 with pixi-spine trying to load resources from a cache implemented with indexeddb. All cached files are loaded into patch.files as either blob or text with matching xhrType.

let loader = PIXI.Loader.shared.pre((res, next) => {
    // load files that has been loaded by the patcher.
    if (patch.files[res.url]) {
        res.xhr = patch.files[res.url].xhr;
        res.data = patch.files[res.url].data;
        res.xhrType = this._xhrType(res.url);

        res.complete();
    } else {
        // not loaded by patcher, load on demand using xhr.
        if (!res.url.startsWith(application.realm.resources)) {
            res.url = application.realm.resources + res.url;
        }
    }
    next();
});


// loader.add("resource.json");
// loader.begin(...);

Haven't found any good documentation on using the pre function, my problem here is that I get a hit on the "resource.json" in the cache, but "resource.atlas" and "resource.png" is never requested.

This means I cannot access either the .atlas or .png resource using PIXI.Loader.shared.resources using this method https://github.com/pixijs/pixi-spine/blob/master/examples/preloaded_json.md

This works fine when "resource.json" is NOT in the cache and there are no problems loading plain images like "clouds.png".

 

Please help me, been struggling for a few days ?

Link to comment
Share on other sites

Found this, https://github.com/englercj/resource-loader/blob/release/3.x/src/middleware/caching.js 

I'll check the implementation.

Seems like complete cuts out before middleware is run, which otherwise would have queued the other resources. Maybe I should just manually set the atlas/png resources on the loader when a json file is in the cache.

Edited by codingchili
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...