Phaser API Documentation

  Version: 
setRenderToTexture([key], [flipY])

Description:

Changes this Shader so instead of rendering to the display list it renders to a WebGL Framebuffer and WebGL Texture instead. This allows you to use the output of this shader as an input for another shader, by mapping a sampler2D uniform to it.

After calling this method the Shader.framebuffer and Shader.glTexture properties are populated.

Additionally, you can provide a key to this method. Doing so will create a Phaser Texture from this Shader and save it into the Texture Manager, allowing you to then use it for any texture-based Game Object, such as a Sprite or Image:

var shader = this.add.shader('myShader', x, y, width, height);

shader.setRenderToTexture('doodle');

this.add.image(400, 300, 'doodle');

Note that it stores an active reference to this Shader. That means as this shader updates, so does the texture and any object using it to render with. Also, if you destroy this shader, be sure to clear any objects that may have been using it as a texture too.

You can access the Phaser Texture that is created via the Shader.texture property.

By default it will create a single base texture. You can add frames to the texture by using the Texture.add method. After doing this, you can then allow Game Objects to use a specific frame from a Render Texture.

Parameters:

name type arguments Default description
key string <optional>

The unique key to store the texture as within the global Texture Manager.

flipY boolean <optional> false

Does this texture need vertically flipping before rendering? This should usually be set to true if being fed from a buffer.

Returns:
Description:

This Shader instance.

Since: 3.19.0