| Package | starling.textures |
| Class | public class Texture |
| Inheritance | Texture Object |
| Subclasses | ConcreteTexture, RenderTexture, SubTexture |
A texture stores the information that represents an image. It cannot be added to the display list directly; instead it has to be mapped onto a display object. In Starling, that display object is the class "Image".
Texture FormatsSince textures can be created from a "BitmapData" object, Starling supports any bitmap format that is supported by Flash. And since you can render any Flash display object into a BitmapData object, you can use this to display non-Starling content in Starling - e.g. Shape objects.
Starling also supports ATF textures (Adobe Texture Format), which is a container for compressed texture formats that can be rendered very efficiently by the GPU. Refer to the Flash documentation for more information about this format.
Mip MappingMipMaps are scaled down versions of a texture. When an image is displayed smaller than its natural size, the GPU may display the mip maps instead of the original texture. This reduces aliasing and accelerates rendering. It does, however, also need additional memory; for that reason, you can choose if you want to create them or not.
Texture FrameThe frame property of a texture allows you let a texture appear inside the bounds of an image, leaving a transparent space around the texture. The frame rectangle is specified in the coordinate system of the texture (not the image):
var frame:Rectangle = new Rectangle(-10, -10, 30, 30);
var texture:Texture = Texture.fromTexture(anotherTexture, null, frame);
var image:Image = new Image(texture);
This code would create an image with a size of 30x30, with the texture placed at
x=10, y=10 within that image (assuming that 'anotherTexture' has a width and
height of 10 pixels, it would appear in the middle of the image).
The texture atlas makes use of this feature, as it allows to crop transparent edges of a texture and making up for the changed size by specifying the original texture frame. Tools like TexturePacker use this to optimize the atlas.
Texture CoordinatesIf, on the other hand, you want to show only a part of the texture in an image (i.e. to crop the the texture), you can either create a subtexture (with the method 'Texture.fromTexture()' and specifying a rectangle for the region), or you can manipulate the texture coordinates of the image object. The method 'image.setTexCoords' allows you to do that.
See also
| Property | Defined By | ||
|---|---|---|---|
| base : TextureBase [read-only] The Stage3D texture object the texture is based on. | Texture | ||
| frame : Rectangle [read-only] The texture frame (see class description). | Texture | ||
| height : Number [read-only] The height of the texture in pixels. | Texture | ||
| mipMapping : Boolean [read-only] Indicates if the texture contains mip maps. | Texture | ||
| premultipliedAlpha : Boolean [read-only] Indicates if the alpha values are premultiplied into the RGB values. | Texture | ||
| repeat : Boolean Indicates if the texture should repeat like a wallpaper or stretch the outermost pixels. | Texture | ||
| scale : Number [read-only] The scale factor, which influences width and height properties. | Texture | ||
| width : Number [read-only] The width of the texture in pixels. | Texture | ||
| Method | Defined By | ||
|---|---|---|---|
adjustVertexData(vertexData:VertexData, vertexID:int, count:int):void Converts texture coordinates and vertex positions of raw vertex data into the format
required for rendering. | Texture | ||
dispose():void Disposes the underlying texture data. | Texture | ||
empty(width:int = 64, height:int = 64, color:uint = 0xffffffff, optimizeForRenderTexture:Boolean = false, scale:Number = -1):Texture [static] Creates an empty texture of a certain size and color. | Texture | ||
fromAtfData(data:ByteArray, scale:Number = 1):Texture [static] Creates a texture from the compressed ATF format. | Texture | ||
fromBitmap(data:Bitmap, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):Texture [static] Creates a texture object from a bitmap. | Texture | ||
fromBitmapData(data:BitmapData, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):Texture [static] Creates a texture from bitmap data. | Texture | ||
[static] Creates a texture that contains a region (in pixels) of another texture. | Texture | ||
uploadAtfData(nativeTexture:Texture, data:ByteArray, offset:int = 0):void [static] Uploads ATF data from a ByteArray to a native texture. | Texture | ||
uploadBitmapData(nativeTexture:Texture, data:BitmapData, generateMipmaps:Boolean):void [static] Uploads the bitmap data to the native texture, optionally creating mipmaps. | Texture | ||
| base | property |
base:TextureBase [read-only] The Stage3D texture object the texture is based on.
public function get base():TextureBase| frame | property |
frame:Rectangle [read-only] The texture frame (see class description).
public function get frame():Rectangle| height | property |
height:Number [read-only] The height of the texture in pixels.
public function get height():Number| mipMapping | property |
mipMapping:Boolean [read-only] Indicates if the texture contains mip maps.
public function get mipMapping():Boolean| premultipliedAlpha | property |
premultipliedAlpha:Boolean [read-only] Indicates if the alpha values are premultiplied into the RGB values.
public function get premultipliedAlpha():Boolean| repeat | property |
repeat:BooleanIndicates if the texture should repeat like a wallpaper or stretch the outermost pixels. Note: this makes sense only in textures with sidelengths that are powers of two and that are not loaded from a texture atlas (i.e. no subtextures).
The default value is false.
public function get repeat():Boolean public function set repeat(value:Boolean):void| scale | property |
scale:Number [read-only] The scale factor, which influences width and height properties.
public function get scale():Number| width | property |
width:Number [read-only] The width of the texture in pixels.
public function get width():Number| adjustVertexData | () | method |
public function adjustVertexData(vertexData:VertexData, vertexID:int, count:int):voidConverts texture coordinates and vertex positions of raw vertex data into the format required for rendering.
Parameters
vertexData:VertexData | |
vertexID:int | |
count:int |
| dispose | () | method |
public function dispose():voidDisposes the underlying texture data.
| empty | () | method |
public static function empty(width:int = 64, height:int = 64, color:uint = 0xffffffff, optimizeForRenderTexture:Boolean = false, scale:Number = -1):TextureCreates an empty texture of a certain size and color. The color parameter expects data in ARGB format.
Parameters
width:int (default = 64) | |
height:int (default = 64) | |
color:uint (default = 0xffffffff) | |
optimizeForRenderTexture:Boolean (default = false) | |
scale:Number (default = -1) |
Texture |
| fromAtfData | () | method |
public static function fromAtfData(data:ByteArray, scale:Number = 1):TextureCreates a texture from the compressed ATF format. Beware: you must not dispose 'data' if Starling should handle a lost device context.
Parameters
data:ByteArray | |
scale:Number (default = 1) |
Texture |
| fromBitmap | () | method |
public static function fromBitmap(data:Bitmap, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):TextureCreates a texture object from a bitmap. Beware: you must not dispose 'data' if Starling should handle a lost device context.
Parameters
data:Bitmap | |
generateMipMaps:Boolean (default = true) | |
optimizeForRenderTexture:Boolean (default = false) | |
scale:Number (default = 1) |
Texture |
| fromBitmapData | () | method |
public static function fromBitmapData(data:BitmapData, generateMipMaps:Boolean = true, optimizeForRenderTexture:Boolean = false, scale:Number = 1):TextureCreates a texture from bitmap data. Beware: you must not dispose 'data' if Starling should handle a lost device context.
Parameters
data:BitmapData | |
generateMipMaps:Boolean (default = true) | |
optimizeForRenderTexture:Boolean (default = false) | |
scale:Number (default = 1) |
Texture |
| fromTexture | () | method |
public static function fromTexture(texture:Texture, region:Rectangle = null, frame:Rectangle = null):TextureCreates a texture that contains a region (in pixels) of another texture. The new texture will reference the base texture; no data is duplicated.
Parameters
texture:Texture | |
region:Rectangle (default = null) | |
frame:Rectangle (default = null) |
Texture |
| uploadAtfData | () | method |
public static function uploadAtfData(nativeTexture:Texture, data:ByteArray, offset:int = 0):voidUploads ATF data from a ByteArray to a native texture.
Parameters
nativeTexture:Texture | |
data:ByteArray | |
offset:int (default = 0) |
| uploadBitmapData | () | method |
public static function uploadBitmapData(nativeTexture:Texture, data:BitmapData, generateMipmaps:Boolean):voidUploads the bitmap data to the native texture, optionally creating mipmaps.
Parameters
nativeTexture:Texture | |
data:BitmapData | |
generateMipmaps:Boolean |