LogoPixi’VN
pixi-jsClasses

Class: Loader

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:103

The Loader is responsible for loading all assets, such as images, spritesheets, audio files, etc. It does not do anything clever with URLs - it just loads stuff! Behind the scenes all things are cached using promises. This means it's impossible to load an asset more than once. Through the use of LoaderParsers, the loader can understand how to load any kind of file!

It is not intended that this class is created by developers - its part of the Asset class This is the second major system of PixiJS' main Assets class

Advanced

Constructors

Constructor

> new Loader(): Loader

Returns

Loader

Properties

loadOptions

> loadOptions: LoadOptions

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:134

Options for loading assets with the loader. These options will be used as defaults for all load calls made with this loader instance. They can be overridden by passing options directly to the load method.

Example

// Create a loader with custom default options
const loader = new Loader();
loader.loadOptions = {
  strategy: 'skip', // Default strategy to 'skip'
  retryCount: 5,   // Default retry count to 5
  retryDelay: 500, // Default retry delay to 500ms
};

// This load call will use the loader's default options
await loader.load('image1.png');

***

### parsers

> **parsers**: [`LoaderParser`](/jsdoc/pixi-vn/pixi-js/interfaces/LoaderParser)\<`any`, `any`, `Record`\<`string`, `any`\>\>[]

Defined in: node\_modules/pixi.js/lib/assets/loader/Loader.d.ts:142

All loader parsers registered

***

### promiseCache

> **promiseCache**: `Record`\<`string`, [`PromiseAndParser`](/jsdoc/pixi-vn/pixi-js/interfaces/PromiseAndParser)\>

Defined in: node\_modules/pixi.js/lib/assets/loader/Loader.d.ts:144

Cache loading promises that ae currently active

***

### defaultOptions

> `static` **defaultOptions**: [`LoadOptions`](/jsdoc/pixi-vn/pixi-js/interfaces/LoadOptions)

Defined in: node\_modules/pixi.js/lib/assets/loader/Loader.d.ts:116

Default options for loading assets

#### Example

```ts
// Change default load options globally
Loader.defaultOptions = {
  strategy: 'skip', // Change default strategy to 'skip'
  retryCount: 5,   // Change default retry count to 5
  retryDelay: 500, // Change default retry delay to 500ms
};

Methods

load()

Call Signature

load<T>(assetsToLoadIn, onProgress?): Promise<T>

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:170

Loads one or more assets using the parsers added to the Loader.

Type Parameters
T

T = any

Parameters
assetsToLoadIn

string | ResolvedAsset<any>

urls that you want to load, or a single one!

onProgress?

ProgressCallback | LoadOptions

For multiple asset loading only, an optional function that is called when progress on asset loading is made. The function is passed a single parameter, progress, which represents the percentage (0.0 - 1.0) of the assets loaded. Do not use this function to detect when assets are complete and available, instead use the Promise returned by this function.

Returns

Promise<T>

Example
// Single asset:
const asset = await Loader.load('cool.png');
console.log(asset);

// Multiple assets:
const assets = await Loader.load(['cool.png', 'cooler.png']);
console.log(assets);

Call Signature

load<T>(assetsToLoadIn, onProgress?): Promise<Record<string, T>>

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:171

Loads one or more assets using the parsers added to the Loader.

Type Parameters
T

T = any

Parameters
assetsToLoadIn

string[] | ResolvedAsset<any>[]

urls that you want to load, or a single one!

onProgress?

ProgressCallback | LoadOptions

For multiple asset loading only, an optional function that is called when progress on asset loading is made. The function is passed a single parameter, progress, which represents the percentage (0.0 - 1.0) of the assets loaded. Do not use this function to detect when assets are complete and available, instead use the Promise returned by this function.

Returns

Promise<Record<string, T>>

Example
// Single asset:
const asset = await Loader.load('cool.png');
console.log(asset);

// Multiple assets:
const assets = await Loader.load(['cool.png', 'cooler.png']);
console.log(assets);

reset()

reset(): void

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:146

function used for testing

Returns

void


unload()

unload(assetsToUnloadIn): Promise<void>

Defined in: node_modules/pixi.js/lib/assets/loader/Loader.d.ts:184

Unloads one or more assets. Any unloaded assets will be destroyed, freeing up memory for your app. The parser that created the asset, will be the one that unloads it.

Parameters

assetsToUnloadIn

string | string[] | ResolvedAsset<any> | ResolvedAsset<any>[]

urls that you want to unload, or a single one!

Returns

Promise<void>

Example

// Single asset:
const asset = await Loader.load('cool.png');

await Loader.unload('cool.png');

console.log(asset.destroyed); // true