The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader
const loader = PIXI.loader; // pixi exposes a premade instance for you to use.
//or
const loader = new PIXI.loaders.Loader(); // you can also create your own if you want
const sprites = {};
// Chainable `add` to enqueue a resource
loader.add('bunny', 'data/bunny.png')
.add('spaceship', 'assets/spritesheet.json');
loader.add('scoreFont', 'assets/score.fnt');
// Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource.
// This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc).
loader.pre(cachingMiddleware);
// Chainable `use` to add a middleware that runs for each resource, *after* loading that resource.
// This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc).
loader.use(parsingMiddleware);
// The `load` method loads the queue of resources, and calls the passed in callback called once all
// resources have loaded.
loader.load((loader, resources) => {
// resources is an object where the key is the name of the resource loaded and the value is the resource object.
// They have a couple default properties:
// - `url`: The URL that the resource was loaded from
// - `error`: The error that happened when trying to load (if any)
// - `data`: The raw data that was loaded
// also may contain other properties based on the middleware that runs.
sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture);
sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture);
sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture);
});
// throughout the process multiple signals can be dispatched.
loader.onProgress.add(() => {}); // called once per loaded/errored file
loader.onError.add(() => {}); // called once per errored file
loader.onLoad.add(() => {}); // called once per loaded file
loader.onComplete.add(() => {}); // called once when the queued resources all load.
Public methods | |
---|---|
public static | addPixiMiddleware(fn: function): void |
public static | addPixiMiddleware(fn: function): void |
Adds a default middleware to the pixi loader.
Name | Type | Attribute | Description |
---|---|---|---|
fn | The middleware to add. |
void
Adds a default middleware to the pixi loader.
Name | Type | Attribute | Description |
---|---|---|---|
fn | The middleware to add. |
void
{ "comment": "/**\n *\n * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader\n *\n * ```js\n * const loader = PIXI.loader; // pixi exposes a premade instance for you to use.\n * //or\n * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want\n *\n * const sprites = {};\n *\n * // Chainable `add` to enqueue a resource\n * loader.add('bunny', 'data/bunny.png')\n * .add('spaceship', 'assets/spritesheet.json');\n * loader.add('scoreFont', 'assets/score.fnt');\n *\n * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource.\n * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc).\n * loader.pre(cachingMiddleware);\n *\n * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource.\n * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc).\n * loader.use(parsingMiddleware);\n *\n * // The `load` method loads the queue of resources, and calls the passed in callback called once all\n * // resources have loaded.\n * loader.load((loader, resources) => {\n * // resources is an object where the key is the name of the resource loaded and the value is the resource object.\n * // They have a couple default properties:\n * // - `url`: The URL that the resource was loaded from\n * // - `error`: The error that happened when trying to load (if any)\n * // - `data`: The raw data that was loaded\n * // also may contain other properties based on the middleware that runs.\n * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture);\n * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture);\n * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture);\n * });\n *\n * // throughout the process multiple signals can be dispatched.\n * loader.onProgress.add(() => {}); // called once per loaded/errored file\n * loader.onError.add(() => {}); // called once per errored file\n * loader.onLoad.add(() => {}); // called once per loaded file\n * loader.onComplete.add(() => {}); // called once when the queued resources all load.\n * ```\n *\n * @see https://github.com/englercj/resource-loader\n *\n * @class\n * @extends module:resource-loader.ResourceLoader\n * @memberof PIXI.loaders\n */", "meta": { "range": [ 2706, 3823 ], "filename": "loader.js", "lineno": 61, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\pixi.js\\pixi.js-repo\\src\\loaders", "code": { "id": "astnode100065341", "name": "Loader", "type": "ClassDeclaration", "paramnames": [ "baseUrl", "concurrency" ] } }, "classdesc": "The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader
\n", "see": [ "https://github.com/englercj/resource-loader" ], "kind": "class", "augments": [ "module:resource-loader.ResourceLoader" ], "memberof": "PIXI.loaders", "name": "Loader", "longname": "PIXI.loaders.Loader", "scope": "static", "params": [ { "type": { "names": [ "string" ] }, "optional": true, "defaultvalue": "''", "description": "const loader = PIXI.loader; // pixi exposes a premade instance for you to use.\n//or\nconst loader = new PIXI.loaders.Loader(); // you can also create your own if you want\n\nconst sprites = {};\n\n// Chainable `add` to enqueue a resource\nloader.add('bunny', 'data/bunny.png')\n .add('spaceship', 'assets/spritesheet.json');\nloader.add('scoreFont', 'assets/score.fnt');\n\n// Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource.\n// This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc).\nloader.pre(cachingMiddleware);\n\n// Chainable `use` to add a middleware that runs for each resource, *after* loading that resource.\n// This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc).\nloader.use(parsingMiddleware);\n\n// The `load` method loads the queue of resources, and calls the passed in callback called once all\n// resources have loaded.\nloader.load((loader, resources) => {\n // resources is an object where the key is the name of the resource loaded and the value is the resource object.\n // They have a couple default properties:\n // - `url`: The URL that the resource was loaded from\n // - `error`: The error that happened when trying to load (if any)\n // - `data`: The raw data that was loaded\n // also may contain other properties based on the middleware that runs.\n sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture);\n sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture);\n sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture);\n});\n\n// throughout the process multiple signals can be dispatched.\nloader.onProgress.add(() => {}); // called once per loaded/errored file\nloader.onError.add(() => {}); // called once per errored file\nloader.onLoad.add(() => {}); // called once per loaded file\nloader.onComplete.add(() => {}); // called once when the queued resources all load.
The base url for all resources loaded by this loader.
", "name": "baseUrl" }, { "type": { "names": [ "number" ] }, "optional": true, "defaultvalue": 10, "description": "The number of resources to load concurrently.
", "name": "concurrency" } ], "___id": "T000002R006056", "___s": true, "$methods": [ { "comment": "/**\n * Adds a default middleware to the pixi loader.\n *\n * @static\n * @param {Function} fn - The middleware to add.\n */", "meta": { "range": [ 3740, 3821 ], "filename": "loader.js", "lineno": 91, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\pixi.js\\pixi.js-repo\\src\\loaders", "code": { "id": "astnode100065473", "name": "Loader.addPixiMiddleware", "type": "MethodDefinition", "paramnames": [ "fn" ] }, "vars": { "": null } }, "description": "Adds a default middleware to the pixi loader.
", "scope": "static", "params": [ { "type": { "names": [ "function" ] }, "description": "The middleware to add.
", "name": "fn" } ], "name": "addPixiMiddleware", "longname": "PIXI.loaders.Loader.addPixiMiddleware", "kind": "function", "memberof": "PIXI.loaders.Loader", "___id": "T000002R006059", "___s": true, "skip": true, "slug": "PIXI.loaders.Loader.addPixiMiddleware", "filepath": "loaders\\loader.js" }, { "comment": "/**\n * Adds a default middleware to the pixi loader.\n *\n * @static\n * @param {Function} fn - The middleware to add.\n */", "meta": { "range": [ 3740, 3821 ], "filename": "loader.js", "lineno": 91, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\pixi.js\\pixi.js-repo\\src\\loaders", "code": { "id": "astnode100140152", "name": "Loader.addPixiMiddleware", "type": "MethodDefinition", "paramnames": [ "fn" ] }, "vars": { "": null } }, "description": "Adds a default middleware to the pixi loader.
", "scope": "static", "params": [ { "type": { "names": [ "function" ] }, "description": "The middleware to add.
", "name": "fn" } ], "name": "addPixiMiddleware", "longname": "PIXI.loaders.Loader.addPixiMiddleware", "kind": "function", "memberof": "PIXI.loaders.Loader", "___id": "T000002R012993", "___s": true, "skip": true, "slug": "PIXI.loaders.Loader.addPixiMiddleware", "filepath": "loaders\\loader.js" } ], "$attributes": [], "$staticmethods": [], "$staticproperties": [], "$augments": [ { "name": "module:resource-loader.ResourceLoader" } ], "$augmentedBy": [], "filepath": "loaders\\loader.js" }