LogoPixi’VN
pixi-jsClasses

Class: GenerateTextureSystem

Defined in: node_modules/pixi.js/lib/rendering/renderers/shared/extract/GenerateTextureSystem.d.ts:215

System that manages the generation of textures from display objects in the renderer. This system is responsible for creating reusable textures from containers, sprites, and other display objects. Available through renderer.textureGenerator.

Example

import { Application, Sprite, Graphics } from 'pixi.js';

const app = new Application();
await app.init();

// Create a complex display object
const container = new Container();

const graphics = new Graphics()
    .circle(0, 0, 50)
    .fill('red');

const sprite = new Sprite(texture);
sprite.x = 100;

container.addChild(graphics, sprite);

// Generate a texture from the container
const generatedTexture = app.renderer.textureGenerator.generateTexture({
    target: container,
    resolution: 2,
    antialias: true
});

// Use the generated texture
const newSprite = new Sprite(generatedTexture);
app.stage.addChild(newSprite);

// Clean up when done
generatedTexture.destroy(true);

Features:

  • Convert any display object to a texture
  • Support for custom regions and resolutions
  • Anti-aliasing support
  • Background color configuration
  • Texture source options customization

Common Use Cases:

  • Creating texture atlases dynamically
  • Caching complex container content
  • Generating thumbnails
  • Creating reusable textures from rendered content

Performance Considerations:

  • Generating textures is relatively expensive
  • Cache results when possible
  • Be mindful of resolution and size
  • Clean up unused textures

See

Standard

Implements

Constructors

Constructor

> new GenerateTextureSystem(renderer): GenerateTextureSystem

Defined in: node_modules/pixi.js/lib/rendering/renderers/shared/extract/GenerateTextureSystem.d.ts:222

Parameters

renderer

Renderer

Returns

GenerateTextureSystem

Other

destroy()

> destroy(): void

Defined in: node_modules/pixi.js/lib/rendering/renderers/shared/extract/GenerateTextureSystem.d.ts:260

Generic destroy methods to be overridden by the subclass

Returns

void

Implementation of

System.destroy

rendering

generateTexture()

> generateTexture(options): RenderTexture

Defined in: node_modules/pixi.js/lib/rendering/renderers/shared/extract/GenerateTextureSystem.d.ts:259

Creates a texture from a display object that can be used for creating sprites and other textures. This is particularly useful for optimizing performance when a complex container needs to be reused.

Parameters

options

Container<ContainerChild> | GenerateTextureOptions

Generate texture options or a container to convert to texture

Returns

RenderTexture

A new RenderTexture containing the rendered display object

Example

// Basic usage with a container
const container = new Container();
container.addChild(
    new Graphics()
        .circle(0, 0, 50)
        .fill('red')
);

const texture = renderer.textureGenerator.generateTexture(container);

// Advanced usage with options
const texture = renderer.textureGenerator.generateTexture({
    target: container,
    frame: new Rectangle(0, 0, 100, 100), // Specific region
    resolution: 2,                        // High DPI
    clearColor: '#ff0000',               // Red background
    antialias: true                      // Smooth edges
});

// Create a sprite from the generated texture
const sprite = new Sprite(texture);

// Clean up when done
texture.destroy(true);

See