diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 54e867b..43d2d61 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -430,6 +430,19 @@ // some helper functions.. /** + * Helper function that creates a new sprite based on the source you provide. + * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * + * @static + * @param source {} + * @return {PIXI.Texture} A Texture + */ +Sprite.from = function (source) +{ + return new Sprite(Texture.from(source)); +} + +/** * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId * The frame ids are created when a Texture packer file has been loaded * diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 54e867b..43d2d61 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -430,6 +430,19 @@ // some helper functions.. /** + * Helper function that creates a new sprite based on the source you provide. + * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * + * @static + * @param source {} + * @return {PIXI.Texture} A Texture + */ +Sprite.from = function (source) +{ + return new Sprite(Texture.from(source)); +} + +/** * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId * The frame ids are created when a Texture packer file has been loaded * diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index f1fe8da..2f4cd1f 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -121,7 +121,8 @@ .addAttribute(this.vertexBuffers[i], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); } - + + this.vao = this.vaos[0]; this.currentBlendMode = 99999; }; diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index 54e867b..43d2d61 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -430,6 +430,19 @@ // some helper functions.. /** + * Helper function that creates a new sprite based on the source you provide. + * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * + * @static + * @param source {} + * @return {PIXI.Texture} A Texture + */ +Sprite.from = function (source) +{ + return new Sprite(Texture.from(source)); +} + +/** * Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId * The frame ids are created when a Texture packer file has been loaded * diff --git a/src/core/sprites/webgl/SpriteRenderer.js b/src/core/sprites/webgl/SpriteRenderer.js index f1fe8da..2f4cd1f 100644 --- a/src/core/sprites/webgl/SpriteRenderer.js +++ b/src/core/sprites/webgl/SpriteRenderer.js @@ -121,7 +121,8 @@ .addAttribute(this.vertexBuffers[i], this.shader.attributes.aColor, gl.UNSIGNED_BYTE, true, this.vertByteSize, 3 * 4) .addAttribute(this.vertexBuffers[i], this.shader.attributes.aTextureId, gl.FLOAT, false, this.vertByteSize, 4 * 4); } - + + this.vao = this.vaos[0]; this.currentBlendMode = 99999; }; diff --git a/src/core/textures/Texture.js b/src/core/textures/Texture.js index bdb3f18..c848b68 100644 --- a/src/core/textures/Texture.js +++ b/src/core/textures/Texture.js @@ -411,6 +411,51 @@ }; /** + * Helper function that creates a new Texture based on the source you provide. + * The soucre can be - frame id, image url, video url, canvae element, video element, base texture + * + * @static + * @param source {} + * @return {PIXI.Texture} A Texture + */ +Texture.from = function (source) +{ + //TODO auto detect cross origin.. + //TODO pass in scale mode? + if(typeof source === 'string') + { + var texture = utils.TextureCache[source]; + + if (!texture) + { + // check if its a video.. + var isVideo = source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/) != null; + if(isVideo) + { + return Texture.fromVideoUrl(source); + } + + return Texture.fromImage(source); + } + + return texture + } + else if(source instanceof HTMLCanvasElement) + { + return Texture.fromCanvas(source); + } + else if(source instanceof HTMLVideoElement) + { + return Texture.fromVideo(source); + } + else if(source instanceof BaseTexture) + { + return new Texture(BaseTexture); + } +} + + +/** * Adds a texture to the global utils.TextureCache. This cache is shared across the whole PIXI object. * * @static