Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Pixi loader? #6176

Closed
softshape opened this issue Oct 15, 2019 · 3 comments
Closed

Extending Pixi loader? #6176

softshape opened this issue Oct 15, 2019 · 3 comments

Comments

@softshape
Copy link

Is there any way to extend Pixi loader or write custom loader? I want to add SVGZ support which basically means I need to deflate gzipped loaded content to a proper SVG before Pixi would process it.

@bigtimebuddy
Copy link
Member

PixiJS v5 introduced registerPlugin to the Loader:
http://pixijs.download/dev/docs/PIXI.Loader.html#.registerPlugin

This allows you to create your own middleware to handle custom media types. Here's a rough example of how you might do this:

const SVGZLoaderPlugin = {
  add() {
    // handle loading SVGZ files as an ArrayBuffer
    PIXI.LoaderResource.setExtensionXhrType(
      'svgz', LoaderResource.XHR_RESPONSE_TYPE.BUFFER);
    PIXI.LoaderResource.setExtensionLoadType(
      'svgz', LoaderResource.LOAD_TYPE.XHR);
  },
  use(resource, next) {
    // deflate SVGZ
    next();
  }
};
PIXI.Loader.registerPlugin(SVGZLoaderPlugin);

You can also refer to https://github.com/englercj/resource-loader for more information about how the Loader works.

Good luck!

@softshape
Copy link
Author

Thank you, Matt! So far upgrading from v4 to v5 causes problems with the loader - it writes "PIXI.loaders.Loader class has moved to PIXI.Loader" deprecation warning and shows black rectangle on the screen until all the images are loaded.

Is there any transition guide or examples how to rewrite old Pixi loader to use the new one?

@bigtimebuddy
Copy link
Member

We have a v5 migration guide here: https://github.com/pixijs/pixi.js/wiki/v5-Migration-Guide

There isn't something specific for Loader. That deprecation warning just lets you know that the namespace changed, but it should still work. If there's something more subtle going on, if you could a new issue with an example of what you're seeing with black rectangles, perhaps we can provide a more graceful experience.

I'm going to close this issue because it seems like the plugin question was resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants