From 7566236d9b7b96f47732fd729a57626912f3969b Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 2 Aug 2018 12:34:57 +0100 Subject: [PATCH] Added `isRenderTexture` property. --- CHANGELOG.md | 1 + src/textures/TextureSource.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f69666c..e3d70b3c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ The process of managing scissors in the WebGLRenderer has been completely rewrit * You can now play animations in reverse! Use the new `Sprite.anims.playReverse` method to play a pre-defined animation in reverse from its starting frame. Or call `Sprite.anims.reverse` to immediately reverse the flow of an already running animation. Animations running in reverse still count towards the repeat total and respect the yoyo flag (thanks @khaleb85) * The `ParticleEmitterManager` now has the Transform component. This means you can now set the position, rotation or scale of the Emitter Manager, and it will influence every Emitter it is rendering. The Managers transform is mixed with that of the Camera. This works in both Canvas and WebGL. * `TextureManager.addRenderTexture` is a new method that will add a Render Texture into the Texture Manager, allowing you to use it as the texture for Game Objects just by using the texture key. Modifying the source Render Texture will immediately modify any Game Objects using it. +* TextureSource has a new boolean property `isRenderTexture` which is set automatically when it's created. ### Updates diff --git a/src/textures/TextureSource.js b/src/textures/TextureSource.js index 93d9710b1..1de889ac0 100644 --- a/src/textures/TextureSource.js +++ b/src/textures/TextureSource.js @@ -47,16 +47,17 @@ var TextureSource = new Class({ * The Texture this TextureSource belongs to. * * @name Phaser.Textures.TextureSource#texture - * @type {string} + * @type {Phaser.Textures.Texture} * @since 3.0.0 */ this.texture = texture; /** - * The source image data. This is either an Image Element, or a Canvas Element. + * The source image data. + * This is either an Image Element, a Canvas Element or a RenderTexture. * * @name Phaser.Textures.TextureSource#image - * @type {(HTMLImageElement|HTMLCanvasElement)} + * @type {(HTMLImageElement|HTMLCanvasElement|Phaser.GameObjects.RenderTexture)} * @since 3.0.0 */ this.image = source; @@ -120,6 +121,15 @@ var TextureSource = new Class({ */ this.isCanvas = (source instanceof HTMLCanvasElement); + /** + * Is the source image a Render Texture? + * + * @name Phaser.Textures.TextureSource#isRenderTexture + * @type {boolean} + * @since 3.12.0 + */ + this.isRenderTexture = (source.type === 'RenderTexture'); + /** * Are the source image dimensions a power of two? * @@ -158,6 +168,10 @@ var TextureSource = new Class({ { this.glTexture = this.renderer.canvasToTexture(this.image); } + else if (this.isRenderTexture) + { + this.glTexture = this.image.texture; + } else { this.glTexture = this.renderer.createTextureFromSource(this.image, this.width, this.height, this.scaleMode);