diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index ff34740..087bfb9 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -445,7 +445,7 @@ * Checks if a point is inside this tiling sprite * @param point {Point} the point to check */ -TilingSprite.prototype.hitTest = function( point ) +TilingSprite.prototype.containsPoint = function( point ) { this.worldTransform.applyInverse(point, tempPoint); @@ -483,3 +483,42 @@ this._uvs = null; }; + +/** + * Helper function that creates a tiling sprite that will use a texture from the TextureCache based on the frameId + * The frame ids are created when a Texture packer file has been loaded + * + * @static + * @param frameId {String} The frame Id of the texture in the cache + * @return {TilingSprite} A new TilingSprite using a texture from the texture cache matching the frameId + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + */ +TilingSprite.fromFrame = function (frameId,width,height) +{ + var texture = utils.TextureCache[frameId]; + + if (!texture) + { + throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this); + } + + return new TilingSprite(texture,width,height); +}; + +/** + * Helper function that creates a sprite that will contain a texture based on an image url + * If the image is not in the texture cache it will be loaded + * + * @static + * @param imageId {String} The image url of the texture + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter + * @param [scaleMode=scaleModes.DEFAULT] {number} if you want to specify the scale mode, see {@link SCALE_MODES} for possible values + * @return {TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id + */ +TilingSprite.fromImage = function (imageId, width, height, crossorigin, scaleMode) +{ + return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); +}; \ No newline at end of file diff --git a/src/extras/TilingSprite.js b/src/extras/TilingSprite.js index ff34740..087bfb9 100644 --- a/src/extras/TilingSprite.js +++ b/src/extras/TilingSprite.js @@ -445,7 +445,7 @@ * Checks if a point is inside this tiling sprite * @param point {Point} the point to check */ -TilingSprite.prototype.hitTest = function( point ) +TilingSprite.prototype.containsPoint = function( point ) { this.worldTransform.applyInverse(point, tempPoint); @@ -483,3 +483,42 @@ this._uvs = null; }; + +/** + * Helper function that creates a tiling sprite that will use a texture from the TextureCache based on the frameId + * The frame ids are created when a Texture packer file has been loaded + * + * @static + * @param frameId {String} The frame Id of the texture in the cache + * @return {TilingSprite} A new TilingSprite using a texture from the texture cache matching the frameId + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + */ +TilingSprite.fromFrame = function (frameId,width,height) +{ + var texture = utils.TextureCache[frameId]; + + if (!texture) + { + throw new Error('The frameId "' + frameId + '" does not exist in the texture cache ' + this); + } + + return new TilingSprite(texture,width,height); +}; + +/** + * Helper function that creates a sprite that will contain a texture based on an image url + * If the image is not in the texture cache it will be loaded + * + * @static + * @param imageId {String} The image url of the texture + * @param width {number} the width of the tiling sprite + * @param height {number} the height of the tiling sprite + * @param [crossorigin=(auto)] {boolean} if you want to specify the cross-origin parameter + * @param [scaleMode=scaleModes.DEFAULT] {number} if you want to specify the scale mode, see {@link SCALE_MODES} for possible values + * @return {TilingSprite} A new TilingSprite using a texture from the texture cache matching the image id + */ +TilingSprite.fromImage = function (imageId, width, height, crossorigin, scaleMode) +{ + return new Sprite(Texture.fromImage(imageId, crossorigin, scaleMode)); +}; \ No newline at end of file diff --git a/src/interaction/interactiveTarget.js b/src/interaction/interactiveTarget.js index 96c57f0..80e039c 100644 --- a/src/interaction/interactiveTarget.js +++ b/src/interaction/interactiveTarget.js @@ -1,4 +1,5 @@ -var core = require('../core'); +var core = require('../core'), + extras = require('../extras'); core.DisplayObject.prototype.interactive = false; @@ -16,4 +17,6 @@ core.Graphics.prototype.hitTest = core.Graphics.prototype.containsPoint; +extras.TilingSprite.prototype.hitTest = extras.TilingSprite.prototype.containsPoint; + module.exports = {};