Options
All
  • Public
  • Public/Protected
  • All
Menu

A RenderTexture is a special texture that allows any PixiJS display object to be rendered to it.

Hint: All DisplayObjects (i.e. Sprites) that render to a RenderTexture should be preloaded otherwise black rectangles will be drawn instead.

Hint-2: The actual memory allocation will happen on first render. You shouldn't create renderTextures each frame just to delete them after, try to reuse them.

A RenderTexture takes a snapshot of any Display Object given to its render method. For example:

let renderer = PIXI.autoDetectRenderer();
let renderTexture = PIXI.RenderTexture.create({ width: 800, height: 600 });
let sprite = PIXI.Sprite.from("spinObj_01.png");

sprite.position.x = 800/2;
sprite.position.y = 600/2;
sprite.anchor.x = 0.5;
sprite.anchor.y = 0.5;

renderer.render(sprite, {renderTexture});

Note that you should not create a new renderer, but reuse the same one as the rest of the application.

The Sprite in this case will be rendered using its local transform. To render this sprite at 0,0 you can clear the transform


sprite.setTransform()

let renderTexture = new PIXI.RenderTexture.create({ width: 100, height: 100 });

renderer.render(sprite, {renderTexture});  // Renders to center of RenderTexture
memberof

PIXI

Hierarchy

Index

Constructors

constructor

Properties

_frame

_frame: Rectangle

Protected _rotate

_rotate: number

_updateID

_updateID: number

_uvs

baseTexture

baseTexture: BaseRenderTexture

defaultAnchor

defaultAnchor: Point

filterFrame

filterFrame: null | Rectangle

filterPoolKey

filterPoolKey: null | string | number

noFrame

noFrame: boolean

orig

orig: Rectangle

Optional patternCache

patternCache: {}

Type declaration

  • [key: string]: CanvasPattern

textureCacheIds

textureCacheIds: string[]

Optional tintCache

tintCache: {}

Type declaration

  • [key: string]: HTMLCanvasElement | HTMLImageElement

trim

trim: Rectangle

uvMatrix

uvMatrix: TextureMatrix

valid

valid: boolean

Static Readonly EMPTY

Static Readonly WHITE

Static prefixed

prefixed: string | boolean

Accessors

frame

  • The frame specifies the region of the base texture that this texture uses. Please call updateUvs() after you change coordinates of frame manually.

    member

    {PIXI.Rectangle}

    Returns Rectangle

  • The frame specifies the region of the base texture that this texture uses. Please call updateUvs() after you change coordinates of frame manually.

    Parameters

    Returns void

framebuffer

  • Shortcut to this.baseTexture.framebuffer, saves baseTexture cast.

    member

    {PIXI.Framebuffer}

    readonly

    Returns Framebuffer

height

  • get height(): number
  • The height of the Texture in pixels.

    member

    {number}

    Returns number

resolution

  • get resolution(): number
  • Returns resolution of baseTexture

    member

    {number}

    readonly

    Returns number

rotate

  • get rotate(): number
  • set rotate(rotate: number): void
  • Indicates whether the texture is rotated inside the atlas set to 2 to compensate for texture packer rotation set to 6 to compensate for spine packer rotation can be used to rotate or mirror sprites See PIXI.groupD8 for explanation

    member

    {number}

    Returns number

  • Indicates whether the texture is rotated inside the atlas set to 2 to compensate for texture packer rotation set to 6 to compensate for spine packer rotation can be used to rotate or mirror sprites See PIXI.groupD8 for explanation

    Parameters

    • rotate: number

    Returns void

width

  • get width(): number
  • The width of the Texture in pixels.

    member

    {number}

    Returns number

Methods

addListener

castToBaseTexture

clone

  • Creates a new texture object that acts the same as this one.

    Returns Texture<Resource>

    The new texture

destroy

  • destroy(destroyBase?: boolean): void
  • Destroys this texture

    Parameters

    • Optional destroyBase: boolean

    Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): (string | symbol)[]
  • Return an array listing the events for which the emitter has registered listeners.

    Returns (string | symbol)[]

listenerCount

  • listenerCount(event: string | symbol): number
  • Return the number of listeners listening to a given event.

    Parameters

    • event: string | symbol

    Returns number

listeners

  • Return the listeners registered for a given event.

    Parameters

    • event: string | symbol

    Returns ListenerFn[]

off

  • Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns RenderTexture

on

  • Add a listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns RenderTexture

Protected onBaseTextureUpdated

once

  • Add a one-time listener for a given event.

    Parameters

    • event: string | symbol
    • fn: ListenerFn
    • Optional context: any

    Returns RenderTexture

removeAllListeners

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: string | symbol

    Returns RenderTexture

removeListener

  • Remove the listeners of a given event.

    Parameters

    • event: string | symbol
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns RenderTexture

resize

  • resize(width: number, height: number, resizeBaseTexture?: boolean): void
  • Resizes the RenderTexture.

    Parameters

    • width: number

      The width to resize to.

    • height: number

      The height to resize to.

    • Optional resizeBaseTexture: boolean

    Returns void

setResolution

  • setResolution(resolution: number): void
  • Changes the resolution of baseTexture, but does not change framebuffer size.

    Parameters

    • resolution: number

      The new resolution to apply to RenderTexture

    Returns void

update

  • update(): void
  • Updates this texture on the gpu.

    Calls the TextureResource update.

    If you adjusted frame manually, please call updateUvs() instead.

    Returns void

updateUvs

  • updateUvs(): void
  • Updates the internal WebGL UV cache. Use it after you change frame or trim of the texture. Call it after changing the frame

    Returns void

Static addToCache

  • Adds a Texture to the global TextureCache. This cache is shared across the whole PIXI object.

    static

    Parameters

    • texture: Texture<Resource>

      The Texture to add to the cache.

    • id: string

      The id that the Texture will be stored against.

    Returns void

Static create

  • Use the object-based construction instead.

    method
    deprecated

    since 6.0.0

    Parameters

    • width: number
    • height: number
    • Optional scaleMode: SCALE_MODES
    • Optional resolution: number

    Returns RenderTexture

  • A short hand way of creating a render texture.

    method

    Parameters

    Returns RenderTexture

    The new render texture

Static from

  • Helper function that creates a new Texture based on the source you provide. The source can be - frame id, image url, video url, canvas element, video element, base texture

    static

    Type parameters

    Parameters

    Returns Texture<R>

    The newly created texture

Static fromBuffer

  • Create a new Texture with a BufferResource from a Float32Array. RGBA values are floats from 0 to 1.

    static

    Parameters

    • buffer: Float32Array | Uint8Array

      The optional array to use, if no data is provided, a new Float32Array is created.

    • width: number

      Width of the resource

    • height: number

      Height of the resource

    • Optional options: IBaseTextureOptions<ISize>

    Returns Texture<BufferResource>

    The resulting new BaseTexture

Static fromLoader

  • fromLoader<R>(source: string | HTMLCanvasElement | HTMLImageElement, imageUrl: string, name?: string, options?: IBaseTextureOptions<any>): Promise<Texture<R>>
  • Create a texture from a source and add to the cache.

    static

    Type parameters

    Parameters

    • source: string | HTMLCanvasElement | HTMLImageElement

      The input source.

    • imageUrl: string

      File name of texture, for cache and resolving resolution.

    • Optional name: string
    • Optional options: IBaseTextureOptions<any>

    Returns Promise<Texture<R>>

    Output texture

Static fromURL

  • Useful for loading textures via URLs. Use instead of Texture.from because it does a better job of handling failed URLs more effectively. This also ignores PIXI.settings.STRICT_TEXTURE_CACHE. Works for Videos, SVGs, Images.

    Type parameters

    Parameters

    Returns Promise<Texture<R>>

    A Promise that resolves to a Texture.

Static removeFromCache

  • Remove a Texture from the global TextureCache.

    static

    Parameters

    • texture: string | Texture<Resource>

      id of a Texture to be removed, or a Texture instance itself

    Returns null | Texture<Resource>

    The Texture that was removed

Generated using TypeDoc