mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Extended ImageFile to support setting from a config object or array of objects.
This commit is contained in:
parent
54ffcc6391
commit
dec57e2915
4 changed files with 53 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: 'c132b6c0-78a6-11e7-b6cf-f39dd7bd053c'
|
||||
build: '5a41ebf0-7925-11e7-9739-c5d8872ffd75'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -42,6 +42,18 @@ var BaseLoader = new Class({
|
|||
this.state = CONST.LOADER_IDLE;
|
||||
},
|
||||
|
||||
setPath: function (path)
|
||||
{
|
||||
if (path.substr(-1) !== '/')
|
||||
{
|
||||
path = path.concat('/');
|
||||
}
|
||||
|
||||
this.path = path;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
addFile: function (file)
|
||||
{
|
||||
if (!this.isReady())
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
var Class = require('../../utils/Class');
|
||||
var CONST = require('../const');
|
||||
var File = require('../File');
|
||||
var GetFastValue = require('../../utils/object/GetFastValue');
|
||||
|
||||
// Phaser.Loader.FileTypes.ImageFile
|
||||
|
||||
|
@ -10,17 +11,34 @@ var ImageFile = new Class({
|
|||
|
||||
initialize:
|
||||
|
||||
// this.load.image('pic', 'assets/pics/taikodrummaster.jpg');
|
||||
// this.load.image({ key: 'pic', texture: 'assets/pics/taikodrummaster.jpg' });
|
||||
// this.load.image({
|
||||
// key: 'bunny',
|
||||
// texture: 'assets/sprites/bunny.png',
|
||||
// xhr: {
|
||||
// user: 'root',
|
||||
// password: 'th3G1bs0n',
|
||||
// timeout: 30,
|
||||
// header: 'Content-Type',
|
||||
// headerValue: 'text/xml'
|
||||
// }
|
||||
// });
|
||||
// this.load.image({ key: 'bunny' });
|
||||
// this.load.image({ key: 'bunny', extension: 'jpg' });
|
||||
function ImageFile (key, url, path, xhrSettings, config)
|
||||
{
|
||||
var fileKey = (typeof key === 'string') ? key : GetFastValue(key, 'key', '');
|
||||
|
||||
var fileConfig = {
|
||||
type: 'image',
|
||||
extension: 'png',
|
||||
extension: GetFastValue(key, 'extension', 'png'),
|
||||
responseType: 'blob',
|
||||
key: key,
|
||||
url: url,
|
||||
key: fileKey,
|
||||
url: GetFastValue(key, 'texture', url),
|
||||
path: path,
|
||||
xhrSettings: xhrSettings,
|
||||
config: config
|
||||
xhrSettings: GetFastValue(key, 'xhr', {}),
|
||||
config: GetFastValue(key, 'config', config)
|
||||
};
|
||||
|
||||
File.call(this, fileConfig);
|
||||
|
|
|
@ -87,11 +87,26 @@ var Loader = new Class({
|
|||
return entry;
|
||||
},
|
||||
|
||||
// key can be either a string, an object or an array of objects
|
||||
image: function (key, url, xhrSettings)
|
||||
{
|
||||
if (Array.isArray(key))
|
||||
{
|
||||
var files = [];
|
||||
|
||||
for (var i = 0; i < key.length; i++)
|
||||
{
|
||||
files.push(this.image(key[i]));
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
else
|
||||
{
|
||||
var file = new ImageFile(key, url, this.path, xhrSettings);
|
||||
|
||||
return this.addFile(file);
|
||||
}
|
||||
},
|
||||
|
||||
animation: function (key, url, xhrSettings)
|
||||
|
|
Loading…
Reference in a new issue