diff --git a/package.json b/package.json index f9c4451..7639364 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.2.2", + "resource-loader": "^1.3.0", "brfs": "^1.2.0" }, "browserify": { diff --git a/package.json b/package.json index f9c4451..7639364 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.2.2", + "resource-loader": "^1.3.0", "brfs": "^1.2.0" }, "browserify": { diff --git a/src/core/math/Point.js b/src/core/math/Point.js index 09c129f..8b0f9ae 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -36,6 +36,25 @@ }; /** + * Copies x and y from the given point + * + * @param p {Point} + */ +Point.prototype.copy = function (p) { + this.set(p.x, p.y); +}; + +/** + * Returns true if the given point is equal to this point + * + * @param p {Point} + * @returns {boolean} + */ +Point.prototype.equals = function (p) { + return (p.x === this.x) && (p.y === this.y); +}; + +/** * Sets the point to a new x and y position. * If y is omitted, both x and y will be set to x. * diff --git a/package.json b/package.json index f9c4451..7639364 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.2.2", + "resource-loader": "^1.3.0", "brfs": "^1.2.0" }, "browserify": { diff --git a/src/core/math/Point.js b/src/core/math/Point.js index 09c129f..8b0f9ae 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -36,6 +36,25 @@ }; /** + * Copies x and y from the given point + * + * @param p {Point} + */ +Point.prototype.copy = function (p) { + this.set(p.x, p.y); +}; + +/** + * Returns true if the given point is equal to this point + * + * @param p {Point} + * @returns {boolean} + */ +Point.prototype.equals = function (p) { + return (p.x === this.x) && (p.y === this.y); +}; + +/** * Sets the point to a new x and y position. * If y is omitted, both x and y will be set to x. * diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index a65ed46..a13962d 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -320,9 +320,17 @@ */ Texture.fromVideo = function (video, scaleMode) { - return new Texture(VideoBaseTexture.baseTextureFromVideo(video, scaleMode)); + return new Texture(VideoBaseTexture.fromVideo(video, scaleMode)); }; +/** + * Helper function that creates a new Texture based on the video url. + * + * @static + * @param videoUrl {string} + * @param scaleMode {number} See {{#crossLink "PIXI/scaleModes:property"}}scaleModes{{/crossLink}} for possible values + * @return {Texture} A Texture + */ Texture.fromVideoUrl = function (videoUrl, scaleMode) { return new Texture(VideoBaseTexture.fromUrl(videoUrl, scaleMode)); diff --git a/package.json b/package.json index f9c4451..7639364 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "async": "^0.9.0", - "resource-loader": "^1.2.2", + "resource-loader": "^1.3.0", "brfs": "^1.2.0" }, "browserify": { diff --git a/src/core/math/Point.js b/src/core/math/Point.js index 09c129f..8b0f9ae 100644 --- a/src/core/math/Point.js +++ b/src/core/math/Point.js @@ -36,6 +36,25 @@ }; /** + * Copies x and y from the given point + * + * @param p {Point} + */ +Point.prototype.copy = function (p) { + this.set(p.x, p.y); +}; + +/** + * Returns true if the given point is equal to this point + * + * @param p {Point} + * @returns {boolean} + */ +Point.prototype.equals = function (p) { + return (p.x === this.x) && (p.y === this.y); +}; + +/** * Sets the point to a new x and y position. * If y is omitted, both x and y will be set to x. * diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index a65ed46..a13962d 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -320,9 +320,17 @@ */ Texture.fromVideo = function (video, scaleMode) { - return new Texture(VideoBaseTexture.baseTextureFromVideo(video, scaleMode)); + return new Texture(VideoBaseTexture.fromVideo(video, scaleMode)); }; +/** + * Helper function that creates a new Texture based on the video url. + * + * @static + * @param videoUrl {string} + * @param scaleMode {number} See {{#crossLink "PIXI/scaleModes:property"}}scaleModes{{/crossLink}} for possible values + * @return {Texture} A Texture + */ Texture.fromVideoUrl = function (videoUrl, scaleMode) { return new Texture(VideoBaseTexture.fromUrl(videoUrl, scaleMode)); diff --git a/src/loaders/bitmapFontParser.js b/src/loaders/bitmapFontParser.js index 7c3b887..f093d2f 100644 --- a/src/loaders/bitmapFontParser.js +++ b/src/loaders/bitmapFontParser.js @@ -1,6 +1,7 @@ var Resource = require('resource-loader').Resource, core = require('../core'), - text = require('../text'); + text = require('../text'), + path = require('path'); module.exports = function () { @@ -23,13 +24,44 @@ var name = resource.data.nodeName; - // skip if no data + // skip if not xml data if (!resource.data || !name || (name.toLowerCase() !== '#document' && name.toLowerCase() !== 'div')) { return next(); } - var textureUrl = resource.data.getElementsByTagName('page')[0].getAttribute('file'); + // skip if not bitmap font data, using some silly duck-typing + if ( + resource.data.getElementsByTagName('page').length === 0 || + resource.data.getElementsByTagName('info').length === 0 || + resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + return next(); + } + + var xmlUrl = path.dirname(resource.url); + + if (xmlUrl === '.') { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') { + xmlUrl += '/'; + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') { + xmlUrl += '/'; + } + } + + var textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); var loadOptions = { crossOrigin: resource.crossOrigin, loadType: Resource.LOAD_TYPE.IMAGE