mirror of
https://github.com/wassname/phaser.git
synced 2026-07-14 01:10:16 +08:00
Added Full Screen support and tested it. Also added in the BitmapText game object and custom XML loader. Game now sends a pause and resume signal, which the TweenManager listens to and handles correctly.
This commit is contained in:
@@ -108,6 +108,25 @@ Phaser.Cache.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new Bitmap Font.
|
||||
* @param key {string} Asset key for the font texture.
|
||||
* @param url {string} URL of this font xml file.
|
||||
* @param data {object} Extra font data.
|
||||
* @param xmlData {object} Texture atlas frames data.
|
||||
*/
|
||||
addBitmapFont: function (key, url, data, xmlData) {
|
||||
|
||||
this._images[key] = { url: url, data: data, spriteSheet: true };
|
||||
|
||||
PIXI.BaseTextureCache[key] = new PIXI.BaseTexture(data);
|
||||
PIXI.TextureCache[key] = new PIXI.Texture(PIXI.BaseTextureCache[key]);
|
||||
|
||||
Phaser.Loader.Parser.bitmapFont(this.game, xmlData, key);
|
||||
// this._images[key].frameData = Phaser.Animation.Parser.XMLData(this.game, xmlData, key);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a default image to be used when a key is wrong / missing.
|
||||
* Is mapped to the key __default
|
||||
|
||||
+119
-18
@@ -217,6 +217,64 @@ Phaser.Loader.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a new bitmap font loading request.
|
||||
* @param key {string} Unique asset key of the bitmap font.
|
||||
* @param textureURL {string} The url of the font image file.
|
||||
* @param [xmlURL] {string} The url of the font data file (xml/fnt)
|
||||
* @param [xmlData] {object} An optional XML data object.
|
||||
*/
|
||||
bitmapFont: function (key, textureURL, xmlURL, xmlData) {
|
||||
|
||||
if (typeof xmlURL === "undefined") { xmlURL = null; }
|
||||
if (typeof xmlData === "undefined") { xmlData = null; }
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
// A URL to a json/xml file has been given
|
||||
if (xmlURL)
|
||||
{
|
||||
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: xmlURL });
|
||||
}
|
||||
else
|
||||
{
|
||||
// An xml string or object has been given
|
||||
if (typeof xmlData === 'string')
|
||||
{
|
||||
var xml;
|
||||
|
||||
try {
|
||||
if (window['DOMParser'])
|
||||
{
|
||||
var domparser = new DOMParser();
|
||||
xml = domparser.parseFromString(xmlData, "text/xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||
xml.async = 'false';
|
||||
xml.loadXML(xmlData);
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
xml = undefined;
|
||||
}
|
||||
|
||||
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
|
||||
{
|
||||
throw new Error("Phaser.Loader. Invalid Bitmap Font XML given");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.addToFileList('bitmapfont', key, textureURL, { xmlURL: null, xmlData: xml });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
atlasJSONArray: function (key, textureURL, atlasURL, atlasData) {
|
||||
|
||||
this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY);
|
||||
@@ -249,20 +307,22 @@ Phaser.Loader.prototype = {
|
||||
if (typeof atlasData === "undefined") { atlasData = null; }
|
||||
if (typeof format === "undefined") { format = Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY; }
|
||||
|
||||
if (this.checkKeyExists(key) === false) {
|
||||
|
||||
if (this.checkKeyExists(key) === false)
|
||||
{
|
||||
// A URL to a json/xml file has been given
|
||||
if (atlasURL) {
|
||||
if (atlasURL)
|
||||
{
|
||||
this.addToFileList('textureatlas', key, textureURL, { atlasURL: atlasURL, format: format });
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (format) {
|
||||
|
||||
switch (format)
|
||||
{
|
||||
// A json string or object has been given
|
||||
case Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY:
|
||||
|
||||
if (typeof atlasData === 'string') {
|
||||
if (typeof atlasData === 'string')
|
||||
{
|
||||
atlasData = JSON.parse(atlasData);
|
||||
}
|
||||
break;
|
||||
@@ -270,24 +330,34 @@ Phaser.Loader.prototype = {
|
||||
// An xml string or object has been given
|
||||
case Phaser.Loader.TEXTURE_ATLAS_XML_STARLING:
|
||||
|
||||
if (typeof atlasData === 'string') {
|
||||
if (typeof atlasData === 'string')
|
||||
{
|
||||
var xml;
|
||||
|
||||
try {
|
||||
if (window['DOMParser']) {
|
||||
if (window['DOMParser'])
|
||||
{
|
||||
var domparser = new DOMParser();
|
||||
xml = domparser.parseFromString(atlasData, "text/xml");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||
xml.async = 'false';
|
||||
xml.loadXML(atlasData);
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
xml = undefined;
|
||||
}
|
||||
|
||||
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length) {
|
||||
if (!xml || !xml.documentElement || xml.getElementsByTagName("parsererror").length)
|
||||
{
|
||||
throw new Error("Phaser.Loader. Invalid Texture Atlas XML given");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
atlasData = xml;
|
||||
}
|
||||
}
|
||||
@@ -298,7 +368,6 @@ Phaser.Loader.prototype = {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
@@ -367,6 +436,7 @@ Phaser.Loader.prototype = {
|
||||
case 'image':
|
||||
case 'spritesheet':
|
||||
case 'textureatlas':
|
||||
case 'bitmapfont':
|
||||
file.data = new Image();
|
||||
file.data.name = file.key;
|
||||
file.data.onload = function () {
|
||||
@@ -537,6 +607,29 @@ Phaser.Loader.prototype = {
|
||||
}
|
||||
break;
|
||||
|
||||
case 'bitmapfont':
|
||||
if (file.xmlURL == null)
|
||||
{
|
||||
this.game.cache.addBitmapFont(file.key, file.url, file.data, file.xmlData);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Load the XML before carrying on with the next file
|
||||
loadNext = false;
|
||||
this._xhr.open("GET", this.baseURL + file.xmlURL, true);
|
||||
this._xhr.responseType = "text";
|
||||
|
||||
this._xhr.onload = function () {
|
||||
return _this.xmlLoadComplete(file.key);
|
||||
};
|
||||
|
||||
this._xhr.onerror = function () {
|
||||
return _this.dataLoadError(file.key);
|
||||
};
|
||||
this._xhr.send();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'audio':
|
||||
|
||||
if (this.game.sound.usingWebAudio)
|
||||
@@ -605,7 +698,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
file.error = true;
|
||||
|
||||
throw new Error("Phaser.Loader dataLoadError: " + key);
|
||||
console.warn("Phaser.Loader dataLoadError: " + key);
|
||||
|
||||
this.nextFile(key, true);
|
||||
|
||||
@@ -613,7 +706,7 @@ Phaser.Loader.prototype = {
|
||||
|
||||
xmlLoadComplete: function (key) {
|
||||
|
||||
var atlasData = this._xhr.response;
|
||||
var data = this._xhr.response;
|
||||
var xml;
|
||||
|
||||
try
|
||||
@@ -621,13 +714,13 @@ Phaser.Loader.prototype = {
|
||||
if (window['DOMParser'])
|
||||
{
|
||||
var domparser = new DOMParser();
|
||||
xml = domparser.parseFromString(atlasData, "text/xml");
|
||||
xml = domparser.parseFromString(data, "text/xml");
|
||||
}
|
||||
else
|
||||
{
|
||||
xml = new ActiveXObject("Microsoft.XMLDOM");
|
||||
xml.async = 'false';
|
||||
xml.loadXML(atlasData);
|
||||
xml.loadXML(data);
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
@@ -641,7 +734,15 @@ Phaser.Loader.prototype = {
|
||||
}
|
||||
|
||||
var file = this._fileList[key];
|
||||
this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
|
||||
|
||||
if (file.type == 'bitmapfont')
|
||||
{
|
||||
this.game.cache.addBitmapFont(file.key, file.url, file.data, xml);
|
||||
}
|
||||
else if (file.type == 'textureatlas')
|
||||
{
|
||||
this.game.cache.addTextureAtlas(file.key, file.url, file.data, xml, file.format);
|
||||
}
|
||||
|
||||
this.nextFile(key, true);
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
Phaser.Loader.Parser = {
|
||||
|
||||
/**
|
||||
* Parse frame data from an XML file.
|
||||
* @param xml {object} XML data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
bitmapFont: function (game, xml, cacheKey) {
|
||||
|
||||
// Malformed?
|
||||
if (!xml.getElementsByTagName('font'))
|
||||
{
|
||||
console.warn("Phaser.Loader.Parser.bitmapFont: Invalid XML given, missing <font> tag");
|
||||
return;
|
||||
}
|
||||
|
||||
var texture = PIXI.TextureCache[cacheKey];
|
||||
|
||||
var data = {};
|
||||
var info = xml.getElementsByTagName("info")[0];
|
||||
var common = xml.getElementsByTagName("common")[0];
|
||||
data.font = info.attributes.getNamedItem("face").nodeValue;
|
||||
data.size = parseInt(info.attributes.getNamedItem("size").nodeValue, 10);
|
||||
data.lineHeight = parseInt(common.attributes.getNamedItem("lineHeight").nodeValue, 10);
|
||||
data.chars = {};
|
||||
|
||||
//parse letters
|
||||
var letters = xml.getElementsByTagName("char");
|
||||
|
||||
for (var i = 0; i < letters.length; i++)
|
||||
{
|
||||
var charCode = parseInt(letters[i].attributes.getNamedItem("id").nodeValue, 10);
|
||||
|
||||
var textureRect = {
|
||||
x: parseInt(letters[i].attributes.getNamedItem("x").nodeValue, 10),
|
||||
y: parseInt(letters[i].attributes.getNamedItem("y").nodeValue, 10),
|
||||
width: parseInt(letters[i].attributes.getNamedItem("width").nodeValue, 10),
|
||||
height: parseInt(letters[i].attributes.getNamedItem("height").nodeValue, 10)
|
||||
};
|
||||
|
||||
// Note: This means you can only have 1 BitmapFont loaded at once!
|
||||
// Need to replace this with our own handler soon.
|
||||
PIXI.TextureCache[charCode] = new PIXI.Texture(texture, textureRect);
|
||||
|
||||
data.chars[charCode] = {
|
||||
xOffset: parseInt(letters[i].attributes.getNamedItem("xoffset").nodeValue, 10),
|
||||
yOffset: parseInt(letters[i].attributes.getNamedItem("yoffset").nodeValue, 10),
|
||||
xAdvance: parseInt(letters[i].attributes.getNamedItem("xadvance").nodeValue, 10),
|
||||
kerning: {},
|
||||
texture:new PIXI.Texture(texture, textureRect)
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
//parse kernings
|
||||
var kernings = xml.getElementsByTagName("kerning");
|
||||
|
||||
for (i = 0; i < kernings.length; i++)
|
||||
{
|
||||
var first = parseInt(kernings[i].attributes.getNamedItem("first").nodeValue, 10);
|
||||
var second = parseInt(kernings[i].attributes.getNamedItem("second").nodeValue, 10);
|
||||
var amount = parseInt(kernings[i].attributes.getNamedItem("amount").nodeValue, 10);
|
||||
|
||||
data.chars[second].kerning[first] = amount;
|
||||
}
|
||||
|
||||
PIXI.BitmapText.fonts[data.font] = data;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user