Bitmap Fonts added
Docs updated
This commit is contained in:
parent
ae98487b16
commit
b378c1ab85
68 changed files with 12469 additions and 3614 deletions
|
@ -45,12 +45,18 @@
|
|||
|
||||
<li><a href="../classes/BaseTexture.html">BaseTexture</a></li>
|
||||
|
||||
<li><a href="../classes/BitmapFontLoader.html">BitmapFontLoader</a></li>
|
||||
|
||||
<li><a href="../classes/BitmapText.html">BitmapText</a></li>
|
||||
|
||||
<li><a href="../classes/CanvasRenderer.html">CanvasRenderer</a></li>
|
||||
|
||||
<li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
|
||||
|
||||
<li><a href="../classes/DisplayObjectContainer.html">DisplayObjectContainer</a></li>
|
||||
|
||||
<li><a href="../classes/ImageLoader.html">ImageLoader</a></li>
|
||||
|
||||
<li><a href="../classes/InteractionData.html">InteractionData</a></li>
|
||||
|
||||
<li><a href="../classes/InteractionManager.html">InteractionManager</a></li>
|
||||
|
@ -127,17 +133,17 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* A Class that loads a bunch of images / sprite sheet files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromFrame(), PIXI.Texture.fromImage() and PIXI.Sprite.fromImage(), PIXI.Sprite.fromFromeId()
|
||||
* When all items have been loaded this class will dispatch a 'loaded' event
|
||||
* As each individual item is loaded this class will dispatch a 'progress' event
|
||||
* A Class that loads a bunch of images / sprite sheet / bitmap font files. Once the assets have been loaded they are added to the PIXI Texture cache and can be accessed easily through PIXI.Texture.fromImage() and PIXI.Sprite.fromImage()
|
||||
* When all items have been loaded this class will dispatch a "onLoaded" event
|
||||
* As each individual item is loaded this class will dispatch a "onProgress" event
|
||||
* @class AssetLoader
|
||||
* @constructor
|
||||
* @extends EventTarget
|
||||
* @param assetURLs {Array} an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported sprite sheet data formats only include "JSON" at this time
|
||||
* @param {Array} assetURLs an array of image/sprite sheet urls that you would like loaded supported. Supported image formats include "jpeg", "jpg", "png", "gif". Supported sprite sheet data formats only include "JSON" at this time. Supported bitmap font data formats include "xml" and "fnt".
|
||||
*/
|
||||
PIXI.AssetLoader = function(assetURLs)
|
||||
{
|
||||
PIXI.EventTarget.call( this );
|
||||
PIXI.EventTarget.call(this);
|
||||
|
||||
/**
|
||||
* The array of asset URLs that are going to be loaded
|
||||
|
@ -145,11 +151,19 @@ PIXI.AssetLoader = function(assetURLs)
|
|||
* @type Array
|
||||
*/
|
||||
this.assetURLs = assetURLs;
|
||||
|
||||
this.assets = [];
|
||||
|
||||
this.crossorigin = false;
|
||||
}
|
||||
|
||||
this.loadersByType = {
|
||||
"jpg": PIXI.ImageLoader,
|
||||
"jpeg": PIXI.ImageLoader,
|
||||
"png": PIXI.ImageLoader,
|
||||
"gif": PIXI.ImageLoader,
|
||||
"json": PIXI.SpriteSheetLoader,
|
||||
"xml": PIXI.BitmapFontLoader,
|
||||
"fnt": PIXI.BitmapFontLoader
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
Fired when an item has loaded
|
||||
|
@ -169,105 +183,45 @@ PIXI.AssetLoader.constructor = PIXI.AssetLoader;
|
|||
*/
|
||||
PIXI.AssetLoader.prototype.load = function()
|
||||
{
|
||||
this.loadCount = this.assetURLs.length;
|
||||
var imageTypes = ["jpeg", "jpg", "png", "gif"];
|
||||
|
||||
var spriteSheetTypes = ["json"];
|
||||
|
||||
for (var i=0; i < this.assetURLs.length; i++)
|
||||
{
|
||||
var filename = this.assetURLs[i];
|
||||
var fileType = filename.split('.').pop().toLowerCase();
|
||||
// what are we loading?
|
||||
var type = null;
|
||||
|
||||
for (var j=0; j < imageTypes.length; j++)
|
||||
{
|
||||
if(fileType == imageTypes[j])
|
||||
{
|
||||
type = "img";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(type != "img")
|
||||
{
|
||||
for (var j=0; j < spriteSheetTypes.length; j++)
|
||||
{
|
||||
if(fileType == spriteSheetTypes[j])
|
||||
{
|
||||
type = "atlas";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(type == "img")
|
||||
{
|
||||
|
||||
var texture = PIXI.Texture.fromImage(filename, this.crossorigin);
|
||||
if(!texture.baseTexture.hasLoaded)
|
||||
{
|
||||
|
||||
var scope = this;
|
||||
texture.baseTexture.addEventListener( 'loaded', function ( event )
|
||||
{
|
||||
scope.onAssetLoaded();
|
||||
});
|
||||
|
||||
this.assets.push(texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// already loaded!
|
||||
this.loadCount--;
|
||||
// if this hits zero here.. then everything was cached!
|
||||
if(this.loadCount == 0)
|
||||
{
|
||||
this.dispatchEvent( { type: 'onComplete', content: this } );
|
||||
if(this.onComplete)this.onComplete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(type == "atlas")
|
||||
{
|
||||
var spriteSheetLoader = new PIXI.SpriteSheetLoader(filename);
|
||||
spriteSheetLoader.crossorigin = this.crossorigin;
|
||||
this.assets.push(spriteSheetLoader);
|
||||
|
||||
var scope = this;
|
||||
spriteSheetLoader.addEventListener( 'loaded', function ( event )
|
||||
{
|
||||
scope.onAssetLoaded();
|
||||
});
|
||||
|
||||
spriteSheetLoader.load();
|
||||
}
|
||||
else
|
||||
{
|
||||
// dont know what the file is! :/
|
||||
//this.loadCount--;
|
||||
throw new Error(filename + " is an unsupported file type " + this);
|
||||
}
|
||||
|
||||
//this.assets[i].load();
|
||||
};
|
||||
}
|
||||
var scope = this;
|
||||
|
||||
this.loadCount = this.assetURLs.length;
|
||||
|
||||
for (var i=0; i < this.assetURLs.length; i++)
|
||||
{
|
||||
var fileName = this.assetURLs[i];
|
||||
var fileType = fileName.split(".").pop().toLowerCase();
|
||||
|
||||
var loaderClass = this.loadersByType[fileType];
|
||||
if(!loaderClass)
|
||||
throw new Error(fileType + " is an unsupported file type");
|
||||
|
||||
var loader = new loaderClass(fileName, this.crossorigin);
|
||||
|
||||
loader.addEventListener("loaded", function()
|
||||
{
|
||||
scope.onAssetLoaded();
|
||||
});
|
||||
loader.load();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Invoked after each file is loaded
|
||||
* @private
|
||||
*/
|
||||
PIXI.AssetLoader.prototype.onAssetLoaded = function()
|
||||
{
|
||||
this.loadCount--;
|
||||
this.dispatchEvent( { type: 'onProgress', content: this } );
|
||||
if(this.onProgress)this.onProgress();
|
||||
this.loadCount--;
|
||||
this.dispatchEvent({type: "onProgress", content: this});
|
||||
if(this.onProgress) this.onProgress();
|
||||
|
||||
if(this.loadCount == 0)
|
||||
{
|
||||
this.dispatchEvent( { type: 'onComplete', content: this } );
|
||||
if(this.onComplete)this.onComplete();
|
||||
this.dispatchEvent({type: "onComplete", content: this});
|
||||
if(this.onComplete) this.onComplete();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
</pre>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue