new TextureAtlas
A TextureAtlas stores multiple images in one square texture and keeps track of the texture coordinates for each image. TextureAtlas is dynamic, meaning new images can be added at any point in time. Calling addImages is more space-efficient than calling addImage multiple times. Texture coordinates are subject to change if the texture atlas resizes, so it is important to check TextureAtlas#getGUID before using old values.
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
description.context |
Context | The context in which the texture gets created. | ||
description.pixelFormat |
PixelFormat |
<optional> |
PixelFormat.RGBA | The pixel format of the texture. |
description.borderWidthInPixels |
Number |
<optional> |
1 | The amount of spacing between adjacent images in pixels. |
description.initialSize |
Cartesian2 |
<optional> |
new Cartesian2(16.0, 16.0) | The initial side lengths of the texture. |
description.images |
Array | Optional array of Image to be added to the atlas. Same as calling addImages(images). | ||
description.image |
Image | Optional single image to be added to the atlas. Same as calling addImage(image). |
Throws:
-
DeveloperError : borderWidthInPixels must be greater than or equal to zero.
-
DeveloperError : initialSize must be greater than zero.
Source:
Members
-
borderWidthInPixels :Number
-
The amount of spacing between adjacent images in pixels.
-
guid :String
-
The atlas' globally unique identifier (GUID). The GUID changes whenever the texture atlas is modified. Classes that use a texture atlas should check if the GUID has changed before processing the atlas data.
-
numberOfImages :Number
-
The number of images in the texture atlas. This value increases every time addImage or addImages is called. Texture coordinates are subject to change if the texture atlas resizes, so it is important to check TextureAtlas#getGUID before using old values.
-
texture :Texture
-
The texture that all of the images are being written to.
-
textureCoordinates :Array
-
An array of BoundingRectangle texture coordinate regions for all the images in the texture atlas. The x and y values of the rectangle correspond to the bottom-left corner of the texture coordinate. The coordinates are in the order that the corresponding images were added to the atlas.
Methods
-
addImage
-
Adds an image to the texture atlas. Calling addImages is more space-efficient than calling addImage multiple times. Texture coordinates are subject to change if the texture atlas resizes, so it is important to check TextureAtlas#getGUID before using old values.
Parameters:
Name Type Description image
Image An image to be added to the texture atlas. Returns:
Number The index of the newly added image. -
addImages
-
Adds an array of images to the texture atlas. Calling addImages is more space-efficient than calling addImage multiple times. Texture coordinates are subject to change if the texture atlas resizes, so it is important to check TextureAtlas#getGUID before using old values.
Parameters:
Name Type Description images
Array An array of Image to be added to the texture atlas. Returns:
Number The first index of the newly added images. -
addSubRegions
-
Add a set of sub-regions to one atlas image as additional image indices.
Parameters:
Name Type Description image
Image An image to be added to the texture atlas. subRegions
Array An array of BoundingRectangle sub-regions measured in pixels from the bottom-left. Returns:
Number The index of the first newly-added region. -
destroy
-
Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.
Once an object is destroyed, it should not be used; calling any function other thanisDestroyed
will result in a DeveloperError exception. Therefore, assign the return value (undefined
) to the object as done in the example.Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.Returns:
Example
atlas = atlas && atlas.destroy();
-
isDestroyed
-
Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other thanisDestroyed
will result in a DeveloperError exception.Returns:
Boolean True if this object was destroyed; otherwise, false.See: