PIXI.BaseTexture

class BaseTexture extends EventEmitter

A Texture stores the information that represents an image. All textures have a base texture, which contains information about the source. Therefore you can have many textures all using a single BaseTexture

Constructor


new PIXI.BaseTexture(resource: PIXI.Resource | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement, options: IBaseTextureOptions<RO>) → {}
Parameters:
Name Type Attributes Default Description
resource PIXI.Resource | string | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement

<optional>

null

The current resource to use, for things that aren't Resource objects, will be converted into a Resource.

options IBaseTextureOptions<RO> undefined

Collection of options

options.mipmap PIXI.MIPMAP_MODES

<optional>

PIXI.settings.MIPMAP_TEXTURES

If mipmapping is enabled for texture

options.anisotropicLevel number

<optional>

PIXI.settings.ANISOTROPIC_LEVEL

Anisotropic filtering level of texture

options.wrapMode PIXI.WRAP_MODES

<optional>

PIXI.settings.WRAP_MODE

Wrap mode for textures

options.scaleMode PIXI.SCALE_MODES

<optional>

PIXI.settings.SCALE_MODE

Default scale mode, linear, nearest

options.format PIXI.FORMATS

<optional>

PIXI.FORMATS.RGBA

GL format type

options.type PIXI.TYPES

<optional>

PIXI.TYPES.UNSIGNED_BYTE

GL data type

options.target PIXI.TARGETS

<optional>

PIXI.TARGETS.TEXTURE_2D

GL texture target

options.alphaMode PIXI.ALPHA_MODES

<optional>

PIXI.ALPHA_MODES.UNPACK

Pre multiply the image alpha

options.width number

<optional>

0

Width of the texture

options.height number

<optional>

0

Height of the texture

options.resolution number

<optional>

PIXI.settings.RESOLUTION

Resolution of the base texture

options.resourceOptions object

<optional>

Optional resource options, see autoDetectResource

Summary


Public Properties


_globalBatch BaseTexture.ts:721
static _globalBatch: number = 0

Global number of the texture batch, used by multi-texture renderers.

_batchEnabled BaseTexture.ts:177
_batchEnabled: number

Number of the texture batch, used by multi-texture renderers

_batchLocation BaseTexture.ts:183
_batchLocation: number

Location inside texture batch, used by multi-texture renderers

alphaMode BaseTexture.ts:69
alphaMode: PIXI.ALPHA_MODES = PIXI.ALPHA_MODES.UNPACK

How to treat premultiplied alpha, see PIXI.ALPHA_MODES.

anisotropicLevel BaseTexture.ts:76
anisotropicLevel: number = PIXI.settings.ANISOTROPIC_LEVEL

Anisotropic filtering level of texture

cacheId BaseTexture.ts:140
cacheId: string

Currently default cache ID.

destroyed BaseTexture.ts:161
destroyed: boolean

Flag if BaseTexture has been destroyed.

dirtyId BaseTexture.ts:127
dirtyId: number

Used by TextureSystem to only update texture to the GPU when needed. Please call update() to increment it.

format BaseTexture.ts:83
format: PIXI.FORMATS = PIXI.FORMATS.RGBA

The pixel format of the texture

height BaseTexture.ts:56
height: number

The height of the base texture set when the image has loaded

isPowerOfTwo BaseTexture.ts:113
isPowerOfTwo: boolean = false

Whether or not the texture is a power of two, try to use power of two textures as much as you can

mipmap BaseTexture.ts:322
mipmap: PIXI.MIPMAP_MODES = PIXI.settings.MIPMAP_TEXTURES

Mipmap mode of the texture, affects downscaled images

parentTextureArray BaseTexture.ts:189
parentTextureArray: PIXI.BaseTexture

Whether its a part of another texture, handled by ArrayResource or CubeResource

realHeight BaseTexture.ts:313
realHeight: number

Pixel height of the source of this texture

realWidth BaseTexture.ts:304
realWidth: number

Pixel width of the source of this texture

resolution BaseTexture.ts:62
resolution: number = PIXI.settings.RESOLUTION

The resolution / device pixel ratio of the texture

resource BaseTexture.ts:168
resource: PIXI.Resource

The resource used by this BaseTexture, there can only be one resource per BaseTexture, but textures can share resources.

scaleMode BaseTexture.ts:339
scaleMode: PIXI.SCALE_MODES = PIXI.settings.SCALE_MODE

The scale mode to apply when scaling this texture

target BaseTexture.ts:95
target: PIXI.TARGETS = PIXI.TARGETS.TEXTURE_2D

The target type

textureCacheIds BaseTexture.ts:153
textureCacheIds: Array<string>

The collection of alternative cache ids, since some BaseTextures can have more than one ID, short name and longer full URL

type BaseTexture.ts:89
type: PIXI.TYPES = PIXI.TYPES.UNSIGNED_BYTE

The type of resource data

valid BaseTexture.ts:146
valid: boolean

Generally speaking means when resource is loaded.

width BaseTexture.ts:50
width: number

The width of the base texture set when the image has loaded

wrapMode BaseTexture.ts:356
wrapMode: PIXI.WRAP_MODES = PIXI.settings.WRAP_MODE

How the texture wraps

Protected Properties


dirtyStyleId BaseTexture.ts:134
protected dirtyStyleId: number

Used by TextureSystem to only update texture style when needed.

touched BaseTexture.ts:107
protected touched: number

Used by automatic texture Garbage Collection, stores last GC tick when it was bound

uid BaseTexture.ts:101
protected uid: number

Global unique identifier for this BaseTexture

Public Methods


addToCache BaseTexture.ts:657
static addToCache(baseTexture: PIXI.BaseTexture, id: string) → {void}

Adds a BaseTexture to the global BaseTextureCache. This cache is shared across the whole PIXI object.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

The BaseTexture to add to the cache.

id string

The id that the BaseTexture will be stored against.

Returns:
Type Description
void
from BaseTexture.ts:579
static from(source: string | Array<string> | HTMLImageElement | HTMLCanvasElement | SVGElement | HTMLVideoElement, options: IBaseTextureOptions<RO>, strict: boolean) → {PIXI.BaseTexture}

Helper function that creates a base texture based on the source you provide. The source can be - image url, image element, canvas element. If the source is an image url or an image element and not in the base texture cache, it will be created and loaded.

Parameters:
Name Type Attributes Default Description
source string | Array<string> | HTMLImageElement | HTMLCanvasElement | SVGElement | HTMLVideoElement

The source to create base texture from.

options IBaseTextureOptions<RO>

<optional>

See PIXI.BaseTexture's constructor for options.

options.pixiIdPrefix string

<optional>

pixiid

If a source has no id, this is the prefix of the generated id

strict boolean

<optional>

Enforce strict-mode, see PIXI.settings.STRICT_TEXTURE_CACHE.

Returns:
Type Description
PIXI.BaseTexture

The new base texture.

fromBuffer BaseTexture.ts:632
static fromBuffer(buffer: Float32Array | Uint8Array, width: number, height: number, options: IBaseTextureOptions) → {PIXI.BaseTexture<PIXI.BufferResource>}

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

Parameters:
Name Type Attributes Default Description
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

options IBaseTextureOptions

<optional>

See PIXI.BaseTexture's constructor for options. Default properties are different from the constructor's defaults.

options.format PIXI.FORMATS

<optional>

PIXI.FORMATS.RGBA

GL format type

options.alphaMode PIXI.ALPHA_MODES

<optional>

PIXI.ALPHA_MODES.NPM

Image alpha, not premultiplied by default

options.scaleMode PIXI.SCALE_MODES

<optional>

PIXI.SCALE_MODES.NEAREST

Scale mode, pixelating by default

Returns:
Type Description
PIXI.BaseTexture<PIXI.BufferResource>
  • The resulting new BaseTexture
removeFromCache BaseTexture.ts:681
static removeFromCache(baseTexture: string | PIXI.BaseTexture) → {PIXI.BaseTexture | unknown}

Remove a BaseTexture from the global BaseTextureCache.

Parameters:
Name Type Description
baseTexture string | PIXI.BaseTexture

id of a BaseTexture to be removed, or a BaseTexture instance itself.

Returns:
Type Description
PIXI.BaseTexture | unknown

The BaseTexture that was removed.

castToBaseTexture BaseTexture.ts:573
castToBaseTexture() → {PIXI.BaseTexture}

Utility function for BaseTexture|Texture cast.

Returns:
Type Description
PIXI.BaseTexture
destroy BaseTexture.ts:526
destroy() → {void}

Destroys this base texture. The method stops if resource doesn't want this texture to be destroyed. Removes texture from all caches.

Returns:
Type Description
void
dispose BaseTexture.ts:562
dispose() → {void}

Frees the texture 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.

Returns:
Type Description
void
getDrawableSource BaseTexture.ts:3
getDrawableSource() → {PIXI.ICanvasImageSource}

Get the drawable source, such as HTMLCanvasElement or HTMLImageElement suitable for rendering with CanvasRenderer. Provided by @pixi/canvas-renderer package.

Returns:
Type Description
PIXI.ICanvasImageSource

Source to render with CanvasRenderer

setRealSize BaseTexture.ts:417
setRealSize(realWidth: number, realHeight: number, resolution: number) → {this}

Sets real size of baseTexture, preserves current resolution.

Parameters:
Name Type Attributes Description
realWidth number

Full rendered width

realHeight number

Full rendered height

resolution number

<optional>

Optionally set resolution

Returns:
Type Description
this
  • this
setResolution BaseTexture.ts:444
setResolution(resolution: number) → {this}

Changes resolution

Parameters:
Name Type Description
resolution number

res

Returns:
Type Description
this
  • this
setResource BaseTexture.ts:472
setResource(resource: R) → {this}

Sets the resource if it wasn't set. Throws error if resource already present

Parameters:
Name Type Description
resource R

that is managing this BaseTexture

Returns:
Type Description
this
  • this
setSize BaseTexture.ts:403
setSize(desiredWidth: number, desiredHeight: number, resolution: number) → {this}

Changes w/h/resolution. Texture becomes valid if width and height are greater than zero.

Parameters:
Name Type Attributes Description
desiredWidth number

Desired visual width

desiredHeight number

Desired visual height

resolution number

<optional>

Optionally set resolution

Returns:
Type Description
this
  • this
setStyle BaseTexture.ts:373
setStyle(scaleMode: PIXI.SCALE_MODES, mipmap: PIXI.MIPMAP_MODES) → {this}

Changes style options of BaseTexture

Parameters:
Name Type Attributes Description
scaleMode PIXI.SCALE_MODES

<optional>

Pixi scalemode

mipmap PIXI.MIPMAP_MODES

<optional>

enable mipmaps

Returns:
Type Description
this
  • this
update BaseTexture.ts:496
update() → {void}

Invalidates the object. Texture becomes valid if width and height are greater than zero.

Returns:
Type Description
void

Events


dispose BaseTexture.ts:293

Fired when BaseTexture is destroyed.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being destroyed.

error BaseTexture.ts:271

Fired when a not-immediately-available source fails to load.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

Resource errored.

event ErrorEvent

Load error event.

loaded BaseTexture.ts:264

Fired when a not-immediately-available source finishes loading.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

loaded BaseTexture.ts:279

Fired when BaseTexture is updated.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

Resource loaded.

update BaseTexture.ts:286

Fired when BaseTexture is updated.

Parameters:
Name Type Description
baseTexture PIXI.BaseTexture

Instance of texture being updated.


Powered by webdoc!