Class: BaseRenderTexture

PIXI~BaseRenderTexture

A BaseRenderTexture 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 BaseRenderTexture should be preloaded 否则将绘制黑色矩形。

A BaseRenderTexture takes a snapshot of any Display Object given to its render method. The position and rotation of the given Display Objects is ignored. For example:

let renderer = PIXI.autoDetectRenderer();
let baseRenderTexture = new PIXI.BaseRenderTexture({ width: 800, height: 600 });
let renderTexture = new PIXI.RenderTexture(baseRenderTexture);
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);

本例中的精灵将使用其局部变换进行渲染。在0,0渲染此精灵 你可以清除转换


sprite.setTransform()

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

renderer.render(sprite, renderTexture);  // 渲染到RenderTexture的中心

new BaseRenderTexture (options)

Name Type Description
options object optional
Name Type Default Description
width number 100 optional

The width of the base render texture.

height number 100 optional

The height of the base render texture.

scaleMode PIXI.SCALE_MODES optional

有关可选值,请参见PIXI.SCALE_MODES.

resolution number 1 optional

生成的纹理的分辨率/设备像素比.

Extends

Members

_batchEnabled number inherited overrides

多纹理渲染器使用的纹理批处理编号

_batchLocation number inherited overrides

纹理批处理中的位置,由多纹理渲染器使用

_canvasRenderTarget object protected

A reference to the canvas render target (we only need one as this can be shared across renderers)

_id number Deprecated : since 5.2.0 inherited overrides

Batch local field, stores current texture location

See:

如何处理预乘alpha, 查看 PIXI.ALPHA_MODES.

Default Value:
  • PIXI.ALPHA_MODES.UNPACK

anisotropicLevel number inherited overrides

各向异性过滤级别的纹理

Default Value:
  • PIXI.settings.ANISOTROPIC_LEVEL

cacheId string inherited overrides

当前默认的缓存ID。

destroyed boolean readonly inherited overrides

标记BaseTexture是否已被销毁。

dirtyId number readonly inherited overrides

TextureSystem用于仅在需要时将纹理更新到GPU。 请调用 update() 增加它。

dirtyStyleId number protected inherited overrides

由TextureSystem使用,仅在需要时更新纹理样式。

filterStack Array.<Object>

The data structure for the filters.

纹理的像素格式

Default Value:
  • PIXI.FORMATS.RGBA

hasLoaded boolean Deprecated : since 5.0.0 readonly inherited overrides

See:

height number readonly inherited overrides

加载图像后设置的基础纹理的高度

imageUrl string Deprecated : since 5.0.0 inherited overrides

See:
  • PIXI.resource.ImageResource#url

isPowerOfTwo boolean readonly inherited overrides

不论纹理是否为2的幂,请尝试尽可能多地使用2的幂

Default Value:
  • false

maskStack Array.<PIXI.MaskData>

The data structure for the stencil masks.

纹理的Mipmap模式,影响缩小的图像

Default Value:
  • PIXI.settings.MIPMAP_TEXTURES

premultiplyAlpha boolean Deprecated : since 5.2.0 readonly inherited overrides

See:

realHeight number readonly inherited overrides

此纹理来源的像素高度

realWidth number readonly inherited overrides

此纹理来源的像素宽度

resolution number inherited overrides

分辨率/纹理的设备像素比率

Default Value:
  • PIXI.settings.RESOLUTION

此BaseTexture使用的资源,每个BaseTexture只能有一个资源,但是纹理可以共享资源。

缩放此纹理时应用的缩放模式

Default Value:
  • PIXI.settings.SCALE_MODE

source HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | SVGElement Deprecated : since 5.0.0 readonly inherited overrides

See:

目标类型

Default Value:
  • PIXI.TARGETS.TEXTURE_2D

textureCacheIds Array.<string> readonly inherited overrides

备用缓存ID的集合,因为某些BaseTextures可以具有多个ID,短名称和更长的完整URL

touched number protected inherited overrides

由自动纹理垃圾收集使用,存储绑定时的最后GC的tick

资源数据的类型

Default Value:
  • PIXI.TYPES.UNSIGNED_BYTE

uid string protected inherited overrides

此BaseTexture的全局唯一标识符

valid boolean readonly inherited overrides

Generally speaking means when resource is loaded.

width number readonly inherited overrides

加载图像后设置的基础纹理的宽度

wrapMode number inherited overrides

纹理如何包裹

Methods

Destroys this texture.

Frees the texture and framebuffer from WebGL memory without destroying this texture object. This means you can still use the texture later which will upload it to GPU memory again.

Fires:

获取可绘制的源,例如HTMLCanvasElement或HTMLImageElement, 它们适合使用CanvasRenderer进行渲染。由 @pixi/canvas-renderer 包提供。

Returns:
Type Description
PIXI.ICanvasImageSource 使用CanvasRenderer渲染的源

loadSource () Deprecated : since 5.0.0 inherited overrides

resize (width, height)

Resizes the BaseRenderTexture.

Name Type Description
width number

要调整大小的宽度。

height number

要调整大小的高度。

setRealSize (realWidth, realHeight, resolution)PIXI.BaseTexture inherited overrides

设置baseTexture的实际大小,保留当前分辨率。

Name Type Description
realWidth number

全渲染宽度

realHeight number

全渲染高度

resolution number optional

(可选)设置分辨率

Returns:
Type Description
PIXI.BaseTexture this

更改分辨率

Name Type Description
resolution number optional

res

Returns:
Type Description
PIXI.BaseTexture this

设置资源(如果未设置)。 如果资源已经存在,则引发错误

Name Type Description
resource PIXI.resources.Resource

管理的BaseTexture

Returns:
Type Description
PIXI.BaseTexture this

setSize (width, height, resolution)PIXI.BaseTexture inherited overrides

更改w/h/分辨率。 如果宽度和高度大于零,则纹理变为有效。

Name Type Description
width number

视觉宽度

height number

视觉高度

resolution number optional

(可选)设置分辨率

Returns:
Type Description
PIXI.BaseTexture this

更改BaseTexture的样式选项

Name Type Description
scaleMode PIXI.SCALE_MODES optional

Pixi scalemode

mipmap PIXI.MIPMAP_MODES optional

开启mipmaps

Returns:
Type Description
PIXI.BaseTexture this

使对象无效。如果宽度和高度大于零,则纹理变为有效。

Events

BaseTexture被销毁时触发。

Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being destroyed.

当非立即可用的源未能加载时触发。

Name Type Description
baseTexture PIXI.BaseTexture

资源错误。

event ErrorEvent

加载错误事件。

当非立即可用的源完成加载时触发。

Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

在更新BaseTexture时触发。

Name Type Description
baseTexture PIXI.BaseTexture

正在更新纹理的实例。