Skip to content

Commit 5b5bdc8

Browse files
committed
Loader.pack will allow you to load in a new Phaser Asset Pack JSON file. An Asset Pack is a specially structured file that allows you to define all assets for your game in an external file. The file can be split into sections, allowing you to control loading a specific set of files from it. An example JSON file can be found in the resources folder and examples of use in the Phaser Examples repository.
Loader.totalQueuedPacks returns the number of Asset Packs in the queue. Loader.totalLoadedPacks returns the number of Asset Packs already loaded.
1 parent 4004cc9 commit 5b5bdc8

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ Version 2.0.6 - "Jornhill" - -in development-
7676
* ArcadePhysics.Body has a new boolean property `enable`. If `false` the body won't be checked for any collision or overlaps, or have its pre or post update methods called. Use this for easy toggling of physics bodies without having to destroy or re-create the Body object itself.
7777
* BitmapData.addToWorld will create a new Phaser.Image object, assign the BitmapData to be its texture, add it to the world then return it.
7878
* BitmapData.copyPixels now accepts a Sprite, Image, BitmapData, HTMLImage or string as its source.
79+
* Loader.pack will allow you to load in a new Phaser Asset Pack JSON file. An Asset Pack is a specially structured file that allows you to define all assets for your game in an external file. The file can be split into sections, allowing you to control loading a specific set of files from it. An example JSON file can be found in the `resources` folder and examples of use in the Phaser Examples repository.
80+
* Loader.totalQueuedPacks returns the number of Asset Packs in the queue.
81+
* Loader.totalLoadedPacks returns the number of Asset Packs already loaded.
7982

8083

8184
### Bug Fixes

build/phaser.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,8 @@ declare module Phaser {
26862686
image(key: string, url: string, overwrite?: boolean): Phaser.Loader;
26872687
json(key: string, url: string, overwrite?: boolean): Phaser.Loader;
26882688
jsonLoadComplete(index: number): void;
2689-
physics(key: string, dataURL?: string, jsonData?: Object, format?: string): Phaser.Loader;
2689+
pack(key: string, url?: string, data?: Object, callbackContext?: any): Phaser.Loader;
2690+
physics(key: string, url?: string, data?: Object, format?: string): Phaser.Loader;
26902691
removeAll(): void;
26912692
removeFile(key: string, type: string): void;
26922693
replaceInFileList(type: string, key: string, url: string, properties: Object): void;
@@ -2696,9 +2697,11 @@ declare module Phaser {
26962697
spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): Phaser.Loader;
26972698
start(): void;
26982699
text(key: string, url: string, overwrite?: boolean): Phaser.Loader;
2699-
tilemap(key: string, mapDataURL?: string, mapData?: Object, format?: number): Phaser.Loader;
2700+
tilemap(key: string, url?: string, data?: Object, format?: number): Phaser.Loader;
27002701
totalLoadedFiles(): number;
2702+
totalLoadedPacks(): number;
27012703
totalQueuedFiles(): number;
2704+
totalQueuedPacks(): number;
27022705
xmlLoadComplete(index: number): void;
27032706

27042707
}

src/loader/Loader.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,17 @@ Phaser.Loader.prototype = {
12751275

12761276
},
12771277

1278+
/**
1279+
* Starts the xhr loader.
1280+
*
1281+
* @method Phaser.Loader#xhrLoad
1282+
* @private
1283+
* @param {number} index - The index of the file to load from the file list.
1284+
* @param {string} url - The URL of the file.
1285+
* @param {string} type - The xhr responseType.
1286+
* @param {string} onload - A String of the name of the local function to be called on a successful file load.
1287+
* @param {string} onerror - A String of the name of the local function to be called on a file load error.
1288+
*/
12781289
xhrLoad: function (index, url, type, onload, onerror) {
12791290

12801291
// console.log('xhrLoad', index, url, type, onload, onerror);
@@ -1298,9 +1309,10 @@ Phaser.Loader.prototype = {
12981309

12991310
/**
13001311
* Private method ONLY used by loader.
1312+
*
13011313
* @method Phaser.Loader#getAudioURL
1302-
* @param {array|string} urls - Either an array of audio file URLs or a string containing a single URL path.
13031314
* @private
1315+
* @param {array|string} urls - Either an array of audio file URLs or a string containing a single URL path.
13041316
*/
13051317
getAudioURL: function (urls) {
13061318

@@ -1624,9 +1636,10 @@ Phaser.Loader.prototype = {
16241636
/**
16251637
* Handle loading next file.
16261638
*
1639+
* @method Phaser.Loader#nextFile
1640+
* @private
16271641
* @param {number} previousIndex - Index of the previously loaded asset.
16281642
* @param {boolean} success - Whether the previous asset loaded successfully or not.
1629-
* @private
16301643
*/
16311644
nextFile: function (previousIndex, success) {
16321645

@@ -1674,6 +1687,7 @@ Phaser.Loader.prototype = {
16741687
/**
16751688
* Returns the number of files that have already been loaded, even if they errored.
16761689
*
1690+
* @method Phaser.Loader#totalLoadedFiles
16771691
* @return {number} The number of files that have already been loaded (even if they errored)
16781692
*/
16791693
totalLoadedFiles: function () {
@@ -1695,6 +1709,7 @@ Phaser.Loader.prototype = {
16951709
/**
16961710
* Returns the number of files still waiting to be processed in the load queue. This value decreases as each file in the queue is loaded.
16971711
*
1712+
* @method Phaser.Loader#totalQueuedFiles
16981713
* @return {number} The number of files that still remain in the load queue.
16991714
*/
17001715
totalQueuedFiles: function () {
@@ -1716,6 +1731,7 @@ Phaser.Loader.prototype = {
17161731
/**
17171732
* Returns the number of asset packs that have already been loaded, even if they errored.
17181733
*
1734+
* @method Phaser.Loader#totalLoadedPacks
17191735
* @return {number} The number of asset packs that have already been loaded (even if they errored)
17201736
*/
17211737
totalLoadedPacks: function () {
@@ -1737,6 +1753,7 @@ Phaser.Loader.prototype = {
17371753
/**
17381754
* Returns the number of asset packs still waiting to be processed in the load queue. This value decreases as each pack in the queue is loaded.
17391755
*
1756+
* @method Phaser.Loader#totalQueuedPacks
17401757
* @return {number} The number of asset packs that still remain in the load queue.
17411758
*/
17421759
totalQueuedPacks: function () {

0 commit comments

Comments
 (0)