Text bug Fixes

Fixed bug with where only 1 bitmap font can be used
Fixed bug when setting Text value to a number value by using toString
This commit is contained in:
Mat Groves 2013-06-05 20:16:00 +01:00
parent 033181171d
commit 14830bf6da
17 changed files with 1523 additions and 717 deletions

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -4,7 +4,7 @@
* Copyright (c) 2012, Mat Groves * Copyright (c) 2012, Mat Groves
* http://goodboydigital.com/ * http://goodboydigital.com/
* *
* Compiled: 2013-05-24 * Compiled: 2013-06-05
* *
* Pixi.JS is licensed under the MIT License. * Pixi.JS is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php * http://www.opensource.org/licenses/mit-license.php
@ -975,7 +975,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };
@ -1212,7 +1213,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -1238,7 +1239,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;
@ -4918,7 +4919,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -4927,7 +4927,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url
@ -5237,7 +5236,7 @@ PIXI.RenderTexture.prototype.initCanvas = function()
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* @method render * @method render
* @param displayObject {DisplayObject} * @param displayObject {DisplayObject}
* @param clear {Boolean} If true the texture will not be cleared before the displayObject is drawn * @param clear {Boolean} If true the texture will be cleared before the displayObject is drawn
*/ */
PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear) PIXI.RenderTexture.prototype.renderWebGL = function(displayObject, clear)
{ {
@ -5403,6 +5402,82 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
}; };
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
* The json file loader is used to load in JSON data and parsing it
* When loaded this class will dispatch a "loaded" event
* If load failed this class will dispatch a "error" event
* @class JsonLoader
* @extends EventTarget
* @constructor
* @param {String} url the url of the JSON file
* @param {Boolean} crossorigin
*/
PIXI.JsonLoader = function (url, crossorigin) {
PIXI.EventTarget.call(this);
this.url = url;
this.baseUrl = url.replace(/[^\/]*$/, "");
this.crossorigin = crossorigin;
};
// constructor
PIXI.JsonLoader.constructor = PIXI.JsonLoader;
/**
* This will begin loading the JSON file
*/
PIXI.JsonLoader.prototype.load = function () {
this.ajaxRequest = new AjaxRequest();
var scope = this;
this.ajaxRequest.onreadystatechange = function () {
scope.onJSONLoaded();
};
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null);
};
/**
* Invoke when JSON file is loaded
* @private
*/
PIXI.JsonLoader.prototype.onJSONLoaded = function () {
if (this.ajaxRequest.readyState == 4) {
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1) {
this.json = JSON.parse(this.ajaxRequest.responseText);
this.onLoaded();
} else {
this.onError();
}
}
};
/**
* Invoke when json file loaded
* @private
*/
PIXI.JsonLoader.prototype.onLoaded = function () {
this.dispatchEvent({
type: "loaded",
content: this
});
};
/**
* Invoke when error occured
* @private
*/
PIXI.JsonLoader.prototype.onError = function () {
this.dispatchEvent({
type: "error",
content: this
});
};
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5422,8 +5497,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
* @param {Boolean} crossorigin * @param {Boolean} crossorigin
*/ */
PIXI.SpriteSheetLoader = function(url, crossorigin) PIXI.SpriteSheetLoader = function (url, crossorigin) {
{
/* /*
* i use texture packer to load the assets.. * i use texture packer to load the assets..
* http://www.codeandweb.com/texturepacker * http://www.codeandweb.com/texturepacker
@ -5443,71 +5517,61 @@ PIXI.SpriteSheetLoader.constructor = PIXI.SpriteSheetLoader;
/** /**
* This will begin loading the JSON file * This will begin loading the JSON file
*/ */
PIXI.SpriteSheetLoader.prototype.load = function() PIXI.SpriteSheetLoader.prototype.load = function () {
{
this.ajaxRequest = new AjaxRequest();
var scope = this; var scope = this;
this.ajaxRequest.onreadystatechange = function() var jsonLoader = new PIXI.JsonLoader(this.url, this.crossorigin);
{ jsonLoader.addEventListener("loaded", function (event) {
scope.json = event.content.json;
scope.onJSONLoaded(); scope.onJSONLoaded();
}; });
jsonLoader.load();
this.ajaxRequest.open("GET", this.url, true);
if (this.ajaxRequest.overrideMimeType) this.ajaxRequest.overrideMimeType("application/json");
this.ajaxRequest.send(null)
}; };
/** /**
* Invoke when JSON file is loaded * Invoke when JSON file is loaded
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function() PIXI.SpriteSheetLoader.prototype.onJSONLoaded = function () {
{
if (this.ajaxRequest.readyState == 4)
{
if (this.ajaxRequest.status == 200 || window.location.href.indexOf("http") == -1)
{
var jsonData = eval("(" + this.ajaxRequest.responseText + ")");
var textureUrl = this.baseUrl + jsonData.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
this.texture = image.texture.baseTexture;
var scope = this; var scope = this;
image.addEventListener("loaded", function(event) { var textureUrl = this.baseUrl + this.json.meta.image;
var image = new PIXI.ImageLoader(textureUrl, this.crossorigin);
var frameData = this.json.frames;
this.texture = image.texture.baseTexture;
image.addEventListener("loaded", function (event) {
scope.onLoaded(); scope.onLoaded();
}); });
var frameData = jsonData.frames; for (var i in frameData) {
for (var i in frameData)
{
var rect = frameData[i].frame; var rect = frameData[i].frame;
if (rect) if (rect) {
{ PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {
PIXI.TextureCache[i] = new PIXI.Texture(this.texture, {x:rect.x, y:rect.y, width:rect.w, height:rect.h}); x: rect.x,
y: rect.y,
if(frameData[i].trimmed) width: rect.w,
{ height: rect.h
});
if (frameData[i].trimmed) {
//var realSize = frameData[i].spriteSourceSize; //var realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize; PIXI.TextureCache[i].realSize = frameData[i].spriteSourceSize;
PIXI.TextureCache[i].trim.x = 0;// (realSize.x / rect.w) PIXI.TextureCache[i].trim.x = 0; // (realSize.x / rect.w)
// calculate the offset! // calculate the offset!
} }
} }
} }
image.load(); image.load();
}
}
}; };
/** /**
* Invoke when all files are loaded (json and texture) * Invoke when all files are loaded (json and texture)
* @private * @private
*/ */
PIXI.SpriteSheetLoader.prototype.onLoaded = function() PIXI.SpriteSheetLoader.prototype.onLoaded = function () {
{ this.dispatchEvent({
this.dispatchEvent({type: "loaded", content: this}); type: "loaded",
content: this
});
}; };
/** /**
* @author Mat Groves http://matgroves.com/ @Doormat23 * @author Mat Groves http://matgroves.com/ @Doormat23
*/ */
@ -5650,7 +5714,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -5665,6 +5731,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -89,7 +89,9 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10), xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10), yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10), xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
kerning: {} kerning: {},
texture:new PIXI.Texture(this.texture, textureRect)
}; };
} }
@ -104,6 +106,7 @@ PIXI.BitmapFontLoader.prototype.onXMLLoaded = function()
data.chars[second].kerning[first] = amount; data.chars[second].kerning[first] = amount;
} }
PIXI.BitmapText.fonts[data.font] = data; PIXI.BitmapText.fonts[data.font] = data;
var scope = this; var scope = this;

View file

@ -97,7 +97,7 @@ PIXI.BitmapText.prototype.updateText = function()
{ {
pos.x += charData.kerning[prevCharCode]; pos.x += charData.kerning[prevCharCode];
} }
chars.push({line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)}); chars.push({texture:charData.texture, line: line, charCode: charCode, position: new PIXI.Point(pos.x + charData.xOffset, pos.y + charData.yOffset)});
pos.x += charData.xAdvance; pos.x += charData.xAdvance;
prevCharCode = charCode; prevCharCode = charCode;
@ -123,7 +123,7 @@ PIXI.BitmapText.prototype.updateText = function()
for(i = 0; i < chars.length; i++) for(i = 0; i < chars.length; i++)
{ {
var char = PIXI.Sprite.fromFrame(chars[i].charCode); var char = new PIXI.Sprite(chars[i].texture)//PIXI.Sprite.fromFrame(chars[i].charCode);
char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale; char.position.x = (chars[i].position.x + lineAlignOffsets[chars[i].line]) * scale;
char.position.y = chars[i].position.y * scale; char.position.y = chars[i].position.y * scale;
char.scale.x = char.scale.y = scale; char.scale.x = char.scale.y = scale;

View file

@ -60,7 +60,8 @@ PIXI.Text.prototype.setStyle = function(style)
*/ */
PIXI.Sprite.prototype.setText = function(text) PIXI.Sprite.prototype.setText = function(text)
{ {
this.text = text || " "; this.text = text.toString() || " ";
this.dirty = true; this.dirty = true;
}; };

View file

@ -90,7 +90,6 @@ PIXI.BaseTexture.constructor = PIXI.BaseTexture;
PIXI.BaseTexture.prototype.destroy = function() PIXI.BaseTexture.prototype.destroy = function()
{ {
if(this.source instanceof Image) if(this.source instanceof Image)
{ {
this.source.src = null; this.source.src = null;
@ -99,7 +98,6 @@ PIXI.BaseTexture.prototype.destroy = function()
PIXI.texturesToDestroy.push(this); PIXI.texturesToDestroy.push(this);
} }
/** /**
* *
* Helper function that returns a base texture based on an image url * Helper function that returns a base texture based on an image url