new PIXI.Texture(baseTexture, frame, crop, trim, rotate)
A texture stores the information that represents an image or part of an image. It cannot be added
to the display list directly. Instead use it as the texture for a Sprite. If no frame is provided then the whole image is used.
You can directly create a texture from an image and then reuse it multiple times like this :
var texture = PIXI.Texture.fromImage('assets/image.png');
var sprite1 = new PIXI.Sprite(texture);
var sprite2 = new PIXI.Sprite(texture);
Name | Type | Description |
---|---|---|
baseTexture |
PIXI.BaseTexture |
The base texture source to create the texture from |
frame |
PIXI.Rectangle |
optional
The rectangle frame of the texture to show |
crop |
PIXI.Rectangle |
optional
The area of original texture |
trim |
PIXI.Rectangle |
optional
Trimmed texture rectangle |
rotate |
number |
optional
indicates how the texture was rotated by texture packer. See PIXI.GroupD8 |
Members
-
static,constantPIXI.Texture.EMPTY
-
An empty texture, used often to not have to create multiple empty textures.
-
baseTexturePIXI.BaseTexture
-
The base texture that this texture uses.
-
cropPIXI.Rectangle
-
This is the area of the BaseTexture image to actually copy to the Canvas / WebGL when rendering,
irrespective of the actual frame size or placement (which can be influenced by trimmed texture atlases) -
framePIXI.Rectangle
-
The frame specifies the region of the base texture that this texture uses.
-
heightnumber
-
The height of the Texture in pixels.
-
noFrameboolean
-
Does this Texture have any frame data assigned to it?
-
requiresUpdateboolean
-
This will let a renderer know that a texture has been updated (used mainly for webGL uv updates)
-
trimPIXI.Rectangle
-
The texture trim data.
-
validboolean
-
This will let the renderer know if the texture is valid. If it's not then it cannot be rendered.
-
widthnumber
-
The width of the Texture in pixels.
Methods
-
staticPIXI.Texture.addTextureToCache(texture, id)
-
Adds a texture to the global utils.TextureCache. This cache is shared across the whole PIXI object.
Name Type Description texture
PIXI.Texture The Texture to add to the cache.
id
string The id that the texture will be stored against.
-
staticPIXI.Texture.fromCanvas(canvas, scaleMode){PIXI.Texture}
-
Helper function that creates a new Texture based on the given canvas element.
Name Type Description canvas
Canvas The canvas element source of the texture
scaleMode
number See PIXI.SCALE_MODES for possible values
Returns:
Type Description PIXI.Texture -
staticPIXI.Texture.fromFrame(frameId){PIXI.Texture}
-
Helper function that creates a sprite that will contain a texture from the TextureCache based on the frameId
The frame ids are created when a Texture packer file has been loadedName Type Description frameId
string The frame Id of the texture in the cache
Returns:
Type Description PIXI.Texture The newly created texture -
staticPIXI.Texture.fromImage(imageUrl, crossorigin, scaleMode){PIXI.Texture}
-
Helper function that creates a Texture object from the given image url.
If the image is not in the texture cache it will be created and loaded.Name Type Description imageUrl
string The image url of the texture
crossorigin
boolean Whether requests should be treated as crossorigin
scaleMode
number See PIXI.SCALE_MODES for possible values
Returns:
Type Description PIXI.Texture The newly created texture -
staticPIXI.Texture.fromVideo(video, scaleMode){PIXI.Texture}
-
Helper function that creates a new Texture based on the given video element.
Name Type Description video
HTMLVideoElement scaleMode
number See PIXI.SCALE_MODES for possible values
Returns:
Type Description PIXI.Texture A Texture -
staticPIXI.Texture.fromVideoUrl(videoUrl, scaleMode){PIXI.Texture}
-
Helper function that creates a new Texture based on the video url.
Name Type Description videoUrl
string scaleMode
number See PIXI.SCALE_MODES for possible values
Returns:
Type Description PIXI.Texture A Texture -
staticPIXI.Texture.removeTextureFromCache(id){PIXI.Texture}
-
Remove a texture from the global utils.TextureCache.
Name Type Description id
string The id of the texture to be removed
Returns:
Type Description PIXI.Texture The texture that was removed -
clone(){PIXI.Texture}
-
Creates a new texture object that acts the same as this one.
Returns:
Type Description PIXI.Texture -
destroy(destroyBase)
-
Destroys this texture
Name Type Default Description destroyBase
boolean false optional Whether to destroy the base texture as well
-
setFrame()
-
- Deprecated
- since version 3.0.0
- See:
-
update()
-
Updates this texture on the gpu.