Skip to content

Render texture


Paste game objects or textures on dynaimc texture, built-in game object of phaser.

  • Author: Richard Davey


Add render texture object

  • Create an empty render texture object.
    var rt = scene.add.renderTexture(x, y, width, height);

Add render texture from JSON

var rt = scene.make.renderTexture({
    x: 0,
    y: 0,
    width: 32,
    height: 32,

    // angle: 0,
    // alpha: 1
    // flipX: true,
    // flipY: true,
    // scale : {
    //    x: 1,
    //    y: 1
    // origin: {x: 0.5, y: 0.5},

    add: true

Origin position

Origin position of this render texture is (0,0) (top-left)

Custom class

  • Define class
    class MyRenderTexture extends Phaser.GameObjects.RenderTexture {
        constructor(scene, x, y, width, height) {
            super(scene, x, y, width, height);
            // ...
        // ...
        // preUpdate(time, delta) {}
    • scene.add.existing(gameObject) : Adds an existing Game Object to this Scene.
      • If the Game Object renders, it will be added to the Display List.
      • If it has a preUpdate method, it will be added to the Update List.
  • Create instance
    var rt = new MyRenderTexture(scene, x, y, width, height);

Paste texture

  • Paste game object
    rt.draw(gameObject, x, y);
    // rt.draw(gameObject, x, y, alpha, tint);
  • gameObject : a game object, or an array of game objects
  • Paste game objects in a group
    rt.draw(group, x, y);
    // rt.draw(group, x, y, alpha, tint);
  • Paste game objects in a scene's display list
    rt.draw(scene.children, x, y);
    // rt.draw(scene.children, x, y, alpha, tint);
  • Paste texture
    rt.draw(key, x, y);
    // rt.draw(key, x, y, alpha, tint);
    rt.drawFrame(key, frame, x, y);
    // rt.drawFrame(key, frame, x, y, alpha, tint);
    • key : The key of the texture to be used, as stored in the Texture Manager.

Global alpha

// rt.globalAlpha = alpha;

Global tint

// rt.globalTint = tint;


rt.erase(gameObject, x, y);
  • gameObject : a game object, or an array of game objects




rt.fill(rgb, alpha);
// rt.fill(rgb, alpha, x, y, width, height);

Set size

rt.setSize(width, height);
// rt.resize(width, height);

Save texture

Stores a copy of this Render Texture in the Texture Manager using the given key.


Calling saveTexture again will not save another copy of the same texture, it will just rename the key of the existing copy.

Internal camera

Internal camera

  • Scroll (offset), y);
  • Zoom (scale);
  • Rotate;  // angle in degrees


  • Takes a snapshot of the whole of this Render Texture.
    // rt.snapshot(callback, type, encoderOptions);
  • Takes a snapshot of the given area of this Render Texture.
    rt.snapshotArea(x, y, width, height, callback);
    // rt.snapshotArea(x, y, width, height, callback, type, encoderOptions);
  • Takes a snapshot of the given pixel from this Render Texture.
    rt.snapshotPixel(x, y, callback);

Other properties

See game object

Create mask

var mask = rt.createBitmapMask();

See mask