/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The image loader class is responsible for loading images file formats ("jpeg", "jpg", "png" and "gif")
* Once the image has been loaded it is stored in the PIXI texture cache and can be accessed though PIXI.Texture.fromFrameId() and PIXI.Sprite.fromFromeId()
* When loaded this class will dispatch a 'loaded' event
*
* @class ImageLoader
* @uses EventTarget
* @constructor
* @param url {String} The url of the image
* @param crossorigin {Boolean} Whether requests should be treated as crossorigin
*/
PIXI.ImageLoader = function(url, crossorigin)
{
PIXI.EventTarget.call(this);
/**
* The texture being loaded
*
* @property texture
* @type Texture
*/
this.texture = PIXI.Texture.fromImage(url, crossorigin);
};
// constructor
PIXI.ImageLoader.prototype.constructor = PIXI.ImageLoader;
/**
* Loads image or takes it from cache
*
* @method load
*/
PIXI.ImageLoader.prototype.load = function()
{
if(!this.texture.baseTexture.hasLoaded)
{
var scope = this;
this.texture.baseTexture.addEventListener("loaded", function()
{
scope.onLoaded();
});
}
else
{
this.onLoaded();
}
};
/**
* Invoked when image file is loaded or it is already cached and ready to use
*
* @method onLoaded
* @private
*/
PIXI.ImageLoader.prototype.onLoaded = function()
{
this.dispatchEvent({type: "loaded", content: this});
};