Skip to content

Commit 4926fac

Browse files
committed
New non-conflicting Loading system in place. Creating tests.
1 parent 2fc5c89 commit 4926fac

6 files changed

Lines changed: 113 additions & 19 deletions

File tree

examples/_site/examples.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,18 @@
388388
}
389389
],
390390
"loader": [
391+
{
392+
"file": "load+audio.js",
393+
"title": "load audio"
394+
},
395+
{
396+
"file": "load+image.js",
397+
"title": "load image"
398+
},
399+
{
400+
"file": "load+spritesheet.js",
401+
"title": "load spritesheet"
402+
},
391403
{
392404
"file": "pick+images+from+cache.js",
393405
"title": "pick images from cache"

examples/loader/load audio.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
3+
4+
function preload() {
5+
6+
// To load an audio file use the following structure.
7+
// As with all load operations the first parameter is a unique key, which must be unique between all audio files.
8+
9+
// The second parameter is an array containing the same audio file but in different formats.
10+
// In this example the music is provided as an mp3 and a ogg (Firefox will want the ogg for example)
11+
12+
// The loader works by checking if the browser can support the first file type in the list (mp3 in this case). If it can, it loads it, otherwise
13+
// it moves to the next file in the list (the ogg). If it can't load any of them the file will error.
14+
15+
game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']);
16+
17+
}
18+
19+
var music;
20+
21+
function create() {
22+
23+
game.stage.backgroundColor = '#182d3b';
24+
25+
// game.input.touch.preventDefault = false;
26+
27+
music = game.sound.play('boden');
28+
29+
}
30+
31+
function render() {
32+
33+
game.debug.renderSoundInfo(music, 32, 32);
34+
35+
}

examples/loader/load image.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
3+
4+
function preload() {
5+
6+
// Specify a unique key and a URL path
7+
// The key must be unique between all images.
8+
game.load.image('imageKey', 'assets/sprites/phaser2.png');
9+
10+
}
11+
12+
function create() {
13+
14+
game.add.sprite(0, 0, 'imageKey');
15+
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
3+
4+
function preload() {
5+
6+
// A sprite sheet is for loading classic "old school" style animations, where each frame
7+
// uses the exact same size frame and there is no configuration file.
8+
9+
// This is different to a Texture Atlas, in which the frames are usually variable in size
10+
// and come with a json or xml file that describes their structure. Sometimes a Texture Atlas
11+
// is called a "sprite sheet" but that isn't the terminology Phaser uses.
12+
13+
// To add a sprite sheet to the loader use the following:
14+
15+
game.load.spritesheet('uniqueKey', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
16+
17+
// 37x45 is the size of each frame
18+
// There are 18 frames in the PNG - you can leave this value blank if the frames fill up the entire PNG, but in this case there are some
19+
// blank frames at the end, so we tell the loader how many to load
20+
21+
}
22+
23+
function create() {
24+
25+
var sprite = game.add.sprite(300, 200, 'uniqueKey');
26+
27+
sprite.animations.add('walk');
28+
29+
sprite.animations.play('walk', 50, true);
30+
31+
}

src/core/StateManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Phaser.StateManager.prototype = {
250250
this.onPreloadCallback.call(this.callbackContext, this.game);
251251

252252
// Is the loader empty?
253-
if (this.game.load.queueSize === 0)
253+
if (this.game.load.totalQueuedFiles() === 0)
254254
{
255255
this.game.loadComplete();
256256
}

src/loader/Loader.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ Phaser.Loader = function (game) {
4646
*/
4747
this._xhr = new XMLHttpRequest();
4848

49-
/**
50-
* @property {number} - Length of assets queue.
51-
* @default
52-
*/
53-
this.queueSize = 0;
54-
5549
/**
5650
* @property {boolean} isLoading - True if the Loader is in the process of loading the queue.
5751
* @default
@@ -250,6 +244,8 @@ Phaser.Loader.prototype = {
250244
loaded: false
251245
};
252246

247+
console.log('addToFileList', entry);
248+
253249
if (typeof properties !== "undefined")
254250
{
255251
for (var prop in properties)
@@ -685,6 +681,8 @@ Phaser.Loader.prototype = {
685681
*/
686682
start: function () {
687683

684+
console.log('Loader start', this._fileList);
685+
688686
if (this.isLoading)
689687
{
690688
return;
@@ -733,10 +731,10 @@ Phaser.Loader.prototype = {
733731
file.data = new Image();
734732
file.data.name = file.key;
735733
file.data.onload = function () {
736-
return _this.fileComplete(this._fileIndex);
734+
return _this.fileComplete(_this._fileIndex);
737735
};
738736
file.data.onerror = function () {
739-
return _this.fileError(this._fileIndex);
737+
return _this.fileError(_this._fileIndex);
740738
};
741739
file.data.crossOrigin = this.crossOrigin;
742740
file.data.src = this.baseURL + file.url;
@@ -753,10 +751,10 @@ Phaser.Loader.prototype = {
753751
this._xhr.open("GET", this.baseURL + file.url, true);
754752
this._xhr.responseType = "arraybuffer";
755753
this._xhr.onload = function () {
756-
return _this.fileComplete(this._fileIndex);
754+
return _this.fileComplete(_this._fileIndex);
757755
};
758756
this._xhr.onerror = function () {
759-
return _this.fileError(this._fileIndex);
757+
return _this.fileError(_this._fileIndex);
760758
};
761759
this._xhr.send();
762760
}
@@ -776,7 +774,7 @@ Phaser.Loader.prototype = {
776774
file.data = new Audio();
777775
file.data.name = file.key;
778776
file.data.onerror = function () {
779-
return _this.fileError(this._fileIndex);
777+
return _this.fileError(_this._fileIndex);
780778
};
781779
file.data.preload = 'auto';
782780
file.data.src = this.baseURL + file.url;
@@ -799,13 +797,13 @@ Phaser.Loader.prototype = {
799797
if (file.format == Phaser.Tilemap.TILED_JSON)
800798
{
801799
this._xhr.onload = function () {
802-
return _this.jsonLoadComplete(this._fileIndex);
800+
return _this.jsonLoadComplete(_this._fileIndex);
803801
};
804802
}
805803
else if (file.format == Phaser.Tilemap.CSV)
806804
{
807805
this._xhr.onload = function () {
808-
return _this.csvLoadComplete(this._fileIndex);
806+
return _this.csvLoadComplete(_this._fileIndex);
809807
};
810808
}
811809
else
@@ -814,7 +812,7 @@ Phaser.Loader.prototype = {
814812
}
815813

816814
this._xhr.onerror = function () {
817-
return _this.dataLoadError(this._fileIndex);
815+
return _this.dataLoadError(_this._fileIndex);
818816
};
819817
this._xhr.send();
820818
break;
@@ -823,10 +821,10 @@ Phaser.Loader.prototype = {
823821
this._xhr.open("GET", this.baseURL + file.url, true);
824822
this._xhr.responseType = "text";
825823
this._xhr.onload = function () {
826-
return _this.fileComplete(this._fileIndex);
824+
return _this.fileComplete(_this._fileIndex);
827825
};
828826
this._xhr.onerror = function () {
829-
return _this.fileError(this._fileIndex);
827+
return _this.fileError(_this._fileIndex);
830828
};
831829
this._xhr.send();
832830
break;
@@ -889,6 +887,8 @@ Phaser.Loader.prototype = {
889887
*/
890888
fileComplete: function (index) {
891889

890+
console.log('fileComplete', index);
891+
892892
if (!this._fileList[index])
893893
{
894894
console.warn('Phaser.Loader fileComplete invalid index ' + index);
@@ -1189,7 +1189,7 @@ Phaser.Loader.prototype = {
11891189

11901190
var total = 0;
11911191

1192-
for (var i = 0; i < this._fileList; i++)
1192+
for (var i = 0; i < this._fileList.length; i++)
11931193
{
11941194
if (this._fileList[i].loaded)
11951195
{
@@ -1210,7 +1210,7 @@ Phaser.Loader.prototype = {
12101210

12111211
var total = 0;
12121212

1213-
for (var i = 0; i < this._fileList; i++)
1213+
for (var i = 0; i < this._fileList.length; i++)
12141214
{
12151215
if (this._fileList[i].loaded === false)
12161216
{

0 commit comments

Comments
 (0)