mirror of
https://github.com/photonstorm/phaser
synced 2025-02-16 14:08:28 +00:00
New non-conflicting Loading system in place. Creating tests.
This commit is contained in:
parent
2fc5c89c1e
commit
4926fac578
6 changed files with 113 additions and 19 deletions
|
@ -388,6 +388,18 @@
|
|||
}
|
||||
],
|
||||
"loader": [
|
||||
{
|
||||
"file": "load+audio.js",
|
||||
"title": "load audio"
|
||||
},
|
||||
{
|
||||
"file": "load+image.js",
|
||||
"title": "load image"
|
||||
},
|
||||
{
|
||||
"file": "load+spritesheet.js",
|
||||
"title": "load spritesheet"
|
||||
},
|
||||
{
|
||||
"file": "pick+images+from+cache.js",
|
||||
"title": "pick images from cache"
|
||||
|
|
35
examples/loader/load audio.js
Normal file
35
examples/loader/load audio.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
// To load an audio file use the following structure.
|
||||
// As with all load operations the first parameter is a unique key, which must be unique between all audio files.
|
||||
|
||||
// The second parameter is an array containing the same audio file but in different formats.
|
||||
// In this example the music is provided as an mp3 and a ogg (Firefox will want the ogg for example)
|
||||
|
||||
// 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
|
||||
// it moves to the next file in the list (the ogg). If it can't load any of them the file will error.
|
||||
|
||||
game.load.audio('boden', ['assets/audio/bodenstaendig_2000_in_rock_4bit.mp3', 'assets/audio/bodenstaendig_2000_in_rock_4bit.ogg']);
|
||||
|
||||
}
|
||||
|
||||
var music;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#182d3b';
|
||||
|
||||
// game.input.touch.preventDefault = false;
|
||||
|
||||
music = game.sound.play('boden');
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSoundInfo(music, 32, 32);
|
||||
|
||||
}
|
16
examples/loader/load image.js
Normal file
16
examples/loader/load image.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
|
||||
|
||||
function preload() {
|
||||
|
||||
// Specify a unique key and a URL path
|
||||
// The key must be unique between all images.
|
||||
game.load.image('imageKey', 'assets/sprites/phaser2.png');
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
game.add.sprite(0, 0, 'imageKey');
|
||||
|
||||
}
|
31
examples/loader/load spritesheet.js
Normal file
31
examples/loader/load spritesheet.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create });
|
||||
|
||||
function preload() {
|
||||
|
||||
// A sprite sheet is for loading classic "old school" style animations, where each frame
|
||||
// uses the exact same size frame and there is no configuration file.
|
||||
|
||||
// This is different to a Texture Atlas, in which the frames are usually variable in size
|
||||
// and come with a json or xml file that describes their structure. Sometimes a Texture Atlas
|
||||
// is called a "sprite sheet" but that isn't the terminology Phaser uses.
|
||||
|
||||
// To add a sprite sheet to the loader use the following:
|
||||
|
||||
game.load.spritesheet('uniqueKey', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
|
||||
// 37x45 is the size of each frame
|
||||
// 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
|
||||
// blank frames at the end, so we tell the loader how many to load
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
var sprite = game.add.sprite(300, 200, 'uniqueKey');
|
||||
|
||||
sprite.animations.add('walk');
|
||||
|
||||
sprite.animations.play('walk', 50, true);
|
||||
|
||||
}
|
|
@ -250,7 +250,7 @@ Phaser.StateManager.prototype = {
|
|||
this.onPreloadCallback.call(this.callbackContext, this.game);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.game.load.queueSize === 0)
|
||||
if (this.game.load.totalQueuedFiles() === 0)
|
||||
{
|
||||
this.game.loadComplete();
|
||||
}
|
||||
|
|
|
@ -46,12 +46,6 @@ Phaser.Loader = function (game) {
|
|||
*/
|
||||
this._xhr = new XMLHttpRequest();
|
||||
|
||||
/**
|
||||
* @property {number} - Length of assets queue.
|
||||
* @default
|
||||
*/
|
||||
this.queueSize = 0;
|
||||
|
||||
/**
|
||||
* @property {boolean} isLoading - True if the Loader is in the process of loading the queue.
|
||||
* @default
|
||||
|
@ -250,6 +244,8 @@ Phaser.Loader.prototype = {
|
|||
loaded: false
|
||||
};
|
||||
|
||||
console.log('addToFileList', entry);
|
||||
|
||||
if (typeof properties !== "undefined")
|
||||
{
|
||||
for (var prop in properties)
|
||||
|
@ -685,6 +681,8 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
start: function () {
|
||||
|
||||
console.log('Loader start', this._fileList);
|
||||
|
||||
if (this.isLoading)
|
||||
{
|
||||
return;
|
||||
|
@ -733,10 +731,10 @@ Phaser.Loader.prototype = {
|
|||
file.data = new Image();
|
||||
file.data.name = file.key;
|
||||
file.data.onload = function () {
|
||||
return _this.fileComplete(this._fileIndex);
|
||||
return _this.fileComplete(_this._fileIndex);
|
||||
};
|
||||
file.data.onerror = function () {
|
||||
return _this.fileError(this._fileIndex);
|
||||
return _this.fileError(_this._fileIndex);
|
||||
};
|
||||
file.data.crossOrigin = this.crossOrigin;
|
||||
file.data.src = this.baseURL + file.url;
|
||||
|
@ -753,10 +751,10 @@ Phaser.Loader.prototype = {
|
|||
this._xhr.open("GET", this.baseURL + file.url, true);
|
||||
this._xhr.responseType = "arraybuffer";
|
||||
this._xhr.onload = function () {
|
||||
return _this.fileComplete(this._fileIndex);
|
||||
return _this.fileComplete(_this._fileIndex);
|
||||
};
|
||||
this._xhr.onerror = function () {
|
||||
return _this.fileError(this._fileIndex);
|
||||
return _this.fileError(_this._fileIndex);
|
||||
};
|
||||
this._xhr.send();
|
||||
}
|
||||
|
@ -776,7 +774,7 @@ Phaser.Loader.prototype = {
|
|||
file.data = new Audio();
|
||||
file.data.name = file.key;
|
||||
file.data.onerror = function () {
|
||||
return _this.fileError(this._fileIndex);
|
||||
return _this.fileError(_this._fileIndex);
|
||||
};
|
||||
file.data.preload = 'auto';
|
||||
file.data.src = this.baseURL + file.url;
|
||||
|
@ -799,13 +797,13 @@ Phaser.Loader.prototype = {
|
|||
if (file.format == Phaser.Tilemap.TILED_JSON)
|
||||
{
|
||||
this._xhr.onload = function () {
|
||||
return _this.jsonLoadComplete(this._fileIndex);
|
||||
return _this.jsonLoadComplete(_this._fileIndex);
|
||||
};
|
||||
}
|
||||
else if (file.format == Phaser.Tilemap.CSV)
|
||||
{
|
||||
this._xhr.onload = function () {
|
||||
return _this.csvLoadComplete(this._fileIndex);
|
||||
return _this.csvLoadComplete(_this._fileIndex);
|
||||
};
|
||||
}
|
||||
else
|
||||
|
@ -814,7 +812,7 @@ Phaser.Loader.prototype = {
|
|||
}
|
||||
|
||||
this._xhr.onerror = function () {
|
||||
return _this.dataLoadError(this._fileIndex);
|
||||
return _this.dataLoadError(_this._fileIndex);
|
||||
};
|
||||
this._xhr.send();
|
||||
break;
|
||||
|
@ -823,10 +821,10 @@ Phaser.Loader.prototype = {
|
|||
this._xhr.open("GET", this.baseURL + file.url, true);
|
||||
this._xhr.responseType = "text";
|
||||
this._xhr.onload = function () {
|
||||
return _this.fileComplete(this._fileIndex);
|
||||
return _this.fileComplete(_this._fileIndex);
|
||||
};
|
||||
this._xhr.onerror = function () {
|
||||
return _this.fileError(this._fileIndex);
|
||||
return _this.fileError(_this._fileIndex);
|
||||
};
|
||||
this._xhr.send();
|
||||
break;
|
||||
|
@ -889,6 +887,8 @@ Phaser.Loader.prototype = {
|
|||
*/
|
||||
fileComplete: function (index) {
|
||||
|
||||
console.log('fileComplete', index);
|
||||
|
||||
if (!this._fileList[index])
|
||||
{
|
||||
console.warn('Phaser.Loader fileComplete invalid index ' + index);
|
||||
|
@ -1189,7 +1189,7 @@ Phaser.Loader.prototype = {
|
|||
|
||||
var total = 0;
|
||||
|
||||
for (var i = 0; i < this._fileList; i++)
|
||||
for (var i = 0; i < this._fileList.length; i++)
|
||||
{
|
||||
if (this._fileList[i].loaded)
|
||||
{
|
||||
|
@ -1210,7 +1210,7 @@ Phaser.Loader.prototype = {
|
|||
|
||||
var total = 0;
|
||||
|
||||
for (var i = 0; i < this._fileList; i++)
|
||||
for (var i = 0; i < this._fileList.length; i++)
|
||||
{
|
||||
if (this._fileList[i].loaded === false)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue