Jump to content

How can Pixijs loader preload Blob data as well?


Recommended Posts

Hi, so I am using Pixijs to load images and other assets but I also want it to load my own proprietary map format as a standard byte array.

    PIXI.loader
      .add(TILEMAP_DATA, { xhrType: PIXI.loaders.Resource.XHR_RESPONSE_TYPE.BLOB })
      .load(this.setup.bind(this));

So I have figured out you can "load" any data with the loader but it doesnt seem to actually load the data? When I check the resource data structure its just a plain Blob structure that I then have to load using this:

    var data = PIXI.loader.resources[tilemap].data;
    let fileReader = new FileReader();
    fileReader.readAsArrayBuffer(data);
    fileReader.onload = function(event) {
      let arrayBuffer = fileReader.result;
      console.log(arrayBuffer);
    };
 

But this is another set of async loading which I don't want. I want the PIXI Loader to actually fetch the whole file data so I can get direct access to the bytes after by just looking it up from PIXI.loader.resources.

Does anyone have any pointers for this?

Link to post
Share on other sites

Ah thanks. Thats brilliant and I guess I should have figured that one out since I actually ask for a Blob there. Never crossed my mind that I could specify something else.

Is there a good resource for Pixijs, the manual/wiki doesn't have very good examples imo. Took me quite some time to figure out how to have same sprite sheet on several sprites but still control their individual rectangles. Most of the examples are pretty hung up on the built in json tilemap feature but I want to have my own custom one if I can as I want more control over each tiles layering and effects.

Link to post
Share on other sites

You're welcome!

Well, PixiJS's documentation is more of an API reference than a user manual. The upside is that it's always up-to-date! The Loader stuff is also a bit different as it's a third-party library, so it's even less documented on pixi's end. I did have to peek around their source code a bit in order to answer your original question.

It's funny that you mention spritesheets without the built-in json format stuff though, I actually did that same thing last week! I had to look at the source code of PIXI.Spritesheet and then implemented my own version.

Link to post
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...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...