| Package | starling.textures |
| Class | public class TextureAtlas |
| Inheritance | TextureAtlas Object |
Using a texture atlas for your textures solves two problems:
By using a texture atlas, you avoid both texture switches and the power-of-two limitation. All textures are within one big "super-texture", and Starling takes care that the correct part of this texture is displayed.
There are several ways to create a texture atlas. One is to use the atlas generator script that is bundled with Starling's sibling, the Sparrow framework. It was only tested in Mac OS X, though. A great multi-platform alternative is the commercial tool Texture Packer.
Whatever tool you use, Starling expects the following file format:
<TextureAtlas imagePath='atlas.png'>
<SubTexture name='texture_1' x='0' y='0' width='50' height='50'/>
<SubTexture name='texture_2' x='50' y='0' width='20' height='30'/>
</TextureAtlas>
If your images have transparent areas at their edges, you can make use of the
frame property of the Texture class. Trim the texture by removing the
transparent edges and specify the original texture size like this:
<SubTexture name='trimmed' x='0' y='0' height='10' width='10'
frameX='-10' frameY='-10' frameWidth='30' frameHeight='30'/>
| Method | Defined By | ||
|---|---|---|---|
TextureAtlas(texture:Texture, atlasXml:XML = null) Create a texture atlas from a texture by parsing the regions from an XML file. | TextureAtlas | ||
addRegion(name:String, region:Rectangle, frame:Rectangle = null):void Creates a region for a subtexture and gives it a name. | TextureAtlas | ||
dispose():void Disposes the atlas texture. | TextureAtlas | ||
getTexture(name:String):Texture Retrieves a subtexture by name. | TextureAtlas | ||
getTextures(prefix:String):Vector.<Texture> Returns all textures that start with a certain string, sorted alphabetically
(especially useful for "MovieClip"). | TextureAtlas | ||
removeRegion(name:String):void Removes a region with a certain name. | TextureAtlas | ||
| TextureAtlas | () | Constructor |
public function TextureAtlas(texture:Texture, atlasXml:XML = null)Create a texture atlas from a texture by parsing the regions from an XML file.
Parameterstexture:Texture | |
atlasXml:XML (default = null) |
| addRegion | () | method |
public function addRegion(name:String, region:Rectangle, frame:Rectangle = null):voidCreates a region for a subtexture and gives it a name.
Parameters
name:String | |
region:Rectangle | |
frame:Rectangle (default = null) |
| dispose | () | method |
public function dispose():voidDisposes the atlas texture.
| getTexture | () | method |
public function getTexture(name:String):Texture Retrieves a subtexture by name. Returns null if it is not found.
Parameters
name:String |
Texture |
| getTextures | () | method |
public function getTextures(prefix:String):Vector.<Texture>Returns all textures that start with a certain string, sorted alphabetically (especially useful for "MovieClip").
Parameters
prefix:String |
Vector.<Texture> |
| removeRegion | () | method |
public function removeRegion(name:String):voidRemoves a region with a certain name.
Parameters
name:String |