phaserjs/phaser/render-textures

Claude Code and agent skill by phaserjs/phaser

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Draw Game Objects, textures and fills into an off-screen texture in Phaser 4 with RenderTexture (this.add.renderTexture) and DynamicTexture (this.textures.addDynamicTexture): draw, stamp, capture, repeat, erase, fill, clear, render, preserve, callback, renderMode, saveTexture, snapshot. Use when making a paint or drawing app, trails, decals, fog of war, a minimap, a composited or procedurally generated texture, a screenshot, or reading a pixel back. Corrects v3 habits: nothing appears until render() is called, draw x/y is an offset added to the object's position, and addDynamicTexture returns null for a key in use. Triggers on: RenderTexture, DynamicTexture, draw to texture, stamp, snapshot, capture, offscreen.

Install

npx vskill@latest install phaserjs/phaser/render-textures

SKILL.md

The same SKILL.md was published earlier as phaserjs/phaser/render-textures.

Render Textures and Dynamic Textures

Drawing into textures at runtime: the DynamicTexture (a texture in the Texture Manager) and the RenderTexture (an Image that owns a DynamicTexture and proxies its drawing methods).

Source: src/textures/DynamicTexture.js, src/gameobjects/rendertexture/RenderTexture.js, src/renderer/webgl/renderNodes/DynamicTextureHandler.js, src/textures/typedefs/StampConfig.js, src/textures/typedefs/CaptureConfig.js. Related: graphics-and-shapes, cameras, masks-and-stencils, sprites-and-images.

Quick start

js
// RenderTexture: a visible Image you draw into. Default size 32x32, origin 0.5.
const rt = this.add.renderTexture(this.scale.width / 2, this.scale.height / 2, 256, 256);
rt.fill(0x222244); // commands run in order: fill first, then draw on top
rt.stamp('player', null, 128, 128); // texture key, frame, x, y (centered by default)
rt.render(); // REQUIRED: nothing is drawn until render()
// DynamicTexture: a shared texture any Game Object can use by key. Default 256x256.
const dt = this.textures.addDynamicTexture('composite', 512, 512);
dt.stamp('coin', null, 64, 64, { scale: 2, angle: 45 });
dt.render();
this.add.image(300, 200, 'composite');

Which one?

  • RenderTexture for one visible drawing surface (paint canvas, trail, composited sprite). It extends Image, so it has position, origin (0.5), scale, alpha, filters, input. Its DynamicTexture is rt.texture, already in the Texture Manager under a random key. rt.saveTexture('name') renames that key so other objects can use it.
  • DynamicTexture when many objects or Scenes share the texture, or it is never shown directly (a mask source, a shader input, a generated spritesheet). Textures are global, so it survives Scene changes until you this.textures.remove(key).
  • Both have the same drawing methods. Each has its own camera.

The command buffer

Drawing methods (draw, stamp, capture, repeat, erase, fill, clear, callback) only queue commands. render() runs them, then empties the buffer. All of them chain.

js
const rt = this.add.renderTexture(0, 0, 512, 512).setOrigin(0);
const ship = this.make.image({ x: 100, y: 100, key: 'ship', add: false }); // only drawn into the texture
rt.clear().fill(0x000000, 0.5).draw(ship).render();
  • preserve(true) keeps the buffer after render(), so the same commands run on every later render(). Queue them once; don't add more each frame or the buffer grows without limit. Start with clear() so they don't pile up on top of each other.
  • callback(fn) queues a function that runs at that point during render().
  • rt.renderMode (RenderTexture only):
ModeEach frame
'render' (default)Draws its texture like an Image. You call render() when the contents change.
'redraw'Calls render() but doesn't draw itself. It must still be visible and on the display list. Use it to refresh a texture other objects show, during the render loop.
'all'Calls render(), then draws itself.

rt.setRenderMode('all', true) also calls preserve(true). With 'redraw' or 'all' and no preserve, only the commands queued since the last frame run.

Drawing

js
const rt = this.add.renderTexture(0, 0, 512, 512).setOrigin(0);
const ship = this.add.image(100, 100, 'ship');
const enemies = this.add.group();
// draw(entries, x, y, alpha, tint)
rt.draw(ship); // at the ship's own position, through the texture's camera
rt.draw(ship, 10, 20); // x and y are ADDED to the ship's position, then put back
rt.draw([ ship, enemies ]); // arrays are drawn whatever their visible state
rt.draw(enemies, 50, 0); // Group, Container, Layer or this.children: offset added to each child
rt.draw('explosion', 200, 200); // texture key: stamped, centered on x, y; alpha and tint apply here only
// stamp(key, frame, x, y, config): a texture frame, ignores the camera
rt.stamp('bullet', null, 100, 100, { alpha: 0.8, tint: 0xff0000, angle: 45, scale: 2, originX: 0, originY: 0, blendMode: 0 });
// capture(gameObject, config): draw with temporary overrides, restored afterwards
rt.capture(ship, { x: 64, y: 64, scale: 0.5, angle: 30, alpha: 0.8 });
// repeat(key, frame, x, y, width, height, config): tile a frame over an area (a TileSprite inside)
rt.repeat('brick', null, 0, 0, 256, 128, { tileScaleX: 2, tileScaleY: 2, tilePositionX: 16 });
rt.erase(ship, 200, 0); // draw with the ERASE blend mode to cut a ship-shaped hole
rt.fill(0x00ff00, 1, 10, 10, 100, 50); // rgb, alpha, x, y, width, height
rt.clear(10, 10, 100, 50); // no arguments clears everything
rt.render();
  • In 4.3 the draw / erase offset works the same in Canvas as in WebGL. To draw a Game Object at an exact spot, pass x - obj.x, y - obj.y, or use capture with x and y.
  • Game Objects use their own alpha, tint and blend mode. The alpha and tint arguments of draw only apply to texture keys and Frames. tint is WebGL only.
  • A Group, Container, Layer or display list only draws children whose willRender passes. Direct entries and arrays are always drawn.
  • An object you only want in the texture shouldn't be on the display list: this.make.image({ key: 'brush', add: false }).
  • An external Mask filter's mask object, or an internal one on a Graphics, Shape, Layer or unsized Container, is placed in world space, so it doesn't follow the draw offset. Move the mask object by the same amount before render() and back after. See masks-and-stencils.
  • A DynamicTexture skips itself. Don't draw a RenderTexture into its own texture.
  • capture config: x, y, alpha, tint, angle (a non-zero angle beats rotation), rotation, scale, scaleX, scaleY, originX, originY, blendMode, camera (render through another Camera), and transform. Pass transform: 'world' to include the transform of the object's parent Container; leave it out, or pass 'local', to use the object's own. It can also be a TransformMatrix.

The texture's camera

rt.camera (the same object as rt.texture.camera) positions Game Objects drawn with draw, capture and repeat. stamp ignores it.

js
const rt = this.add.renderTexture(0, 0, 256, 256);
const ship = this.make.image({ x: 200, y: 150, key: 'ship', add: false });
rt.camera.setScroll(100, 50);
rt.camera.setZoom(2);
rt.draw(ship).render();

Reading pixels back

js
const rt = this.add.renderTexture(0, 0, 256, 256).fill(0xff8800);
rt.render(); // snapshots read the framebuffer, not the queue
rt.snapshot((image) => document.body.appendChild(image)); // HTMLImageElement
rt.snapshotArea(0, 0, 128, 128, (image) => {}, 'image/jpeg', 0.8);
rt.snapshotPixel(64, 64, (color) => console.log(color.r, color.g, color.b, color.a)); // Phaser.Display.Color

Snapshots stall the GPU (readPixels). Don't take them every frame.

Patterns

js
// Paint: stamp a brush where the pointer is, never clearing
const paint = this.add.renderTexture(0, 0, this.scale.width, this.scale.height).setOrigin(0);
this.input.on(Phaser.Input.Events.POINTER_MOVE, (pointer) =>
{
if (pointer.isDown)
{
paint.stamp('brush', null, pointer.x, pointer.y).render();
}
});
// Minimap: a world of 2000x1500 drawn at a tenth of the size, refreshed in update()
const world = this.add.layer(); // add the world's objects to this Layer
const minimap = this.add.renderTexture(this.scale.width - 210, 10, 200, 150).setOrigin(0).setScrollFactor(0);
minimap.camera.setZoom(0.1).centerOn(1000, 750);
// in update():
minimap.clear().fill(0x111111).draw(world).render();

A second Camera with a low zoom is often a simpler minimap: see cameras.

js
// A shared DynamicTexture that survives a Scene restart
const key = 'starfield';
const dt = this.textures.exists(key)
? this.textures.get(key)
: this.textures.addDynamicTexture(key, 512, 512);
dt.clear().fill(0x000011);
for (let i = 0; i < 200; i++)
{
dt.stamp('star', null, Phaser.Math.Between(0, 512), Phaser.Math.Between(0, 512), { alpha: Phaser.Math.FloatBetween(0.3, 1) });
}
dt.render();

Size, keys and lifetime

  • rt.resize(width, height, forceEven = true) / dt.setSize(...) recreate the framebuffer and erase the contents. rt.setSize only changes the Game Object's size, not the texture.
  • Sizes are rounded up to even numbers unless forceEven is false, the last argument of addDynamicTexture, resize and dt.setSize. The this.add.renderTexture factory doesn't take it, so call rt.resize(w, h, false) for an odd size.
  • Destroying a RenderTexture destroys its texture, unless saveTexture was called. A saved texture lives on: remove it with this.textures.remove(key) when done.
  • Mipmaps: framebuffers don't use them unless render: { mipmapFilter: 'LINEAR_MIPMAP_LINEAR', mipmapRegeneration: true } (4.1). They are regenerated after every render(), which costs time.
  • WebGL context loss wipes the contents. Redraw them when the renderer is restored:
js
const dt = this.textures.addDynamicTexture('backdrop', 512, 512);
const redraw = () => dt.clear().fill(0x000011).render();
redraw();
this.renderer.on(Phaser.Renderer.Events.RESTORE_WEBGL, redraw);
this.events.once(Phaser.Scenes.Events.SHUTDOWN, () => this.renderer.off(Phaser.Renderer.Events.RESTORE_WEBGL, redraw));

Gotchas

  1. `render()` is required. Without it, or renderMode 'redraw' / 'all', nothing is drawn.
  2. Order matters. Commands run in the order queued: a fill after a draw covers it.
  3. `addDynamicTexture(key)` returns `null` if the key is in use, and logs an error. On a Scene restart, reuse or remove the old texture first.
  4. Preserved buffers replay. With preserve(true), queue once. Adding commands every frame leaks.
  5. `stamp` ignores the camera; `draw`, `capture` and `repeat` use it.
  6. Stamp origin is 0.5; repeat origin is 0. stamp centers on x, y; repeat fills from its top-left.
  7. Edges in framebuffers. Since 4.3, SDF-drawn Graphics and Shapes (circles, rounded rectangles, lines, strokes) are smooth in a texture. Triangle fills such as polygons and stars have hard edges there, as framebuffers have no multisampling.
  8. `this.add.stamp(x, y, key)` is a Game Object, an Image that ignores camera scroll. It is not the stamp() method.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
39,633
Repository forks
7,130
7-day trend score
53

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 17 May 2026, 6 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Grok Build (Cursor)
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/phaserjs/phaser/render-textures/badge)](https://verified-skill.com/skills/phaserjs/phaser/render-textures)

Something wrong with this skill or its page? Tell us.