Class for packing multiple images in big one and generating frame data for each of them so you can easily load regions of atlas in sprites and tilemaps as a source of graphic

Static variables

@:value(new FlxPoint(1024, 1024))staticdefaultMaxSize:FlxPoint = new FlxPoint(1024, 1024)

Default maximum size for atlases.

@:value(new FlxPoint(128, 128))staticdefaultMinSize:FlxPoint = new FlxPoint(128, 128)

Default minimum size for atlases.

Constructor

@:value({ rotate : false, border : 1, powerOfTwo : false })new(name:String, powerOfTwo:Bool = false, border:Int = 1, rotate:Bool = false, ?minSize:FlxPoint, ?maxSize:FlxPoint)

Atlas constructor

Parameters:

name

The name of this atlas. It will be used for caching BitmapData of this atlas.

powerOfTwo

Whether the size of this atlas should be the power of 2 or not.

border

Gap between nodes to insert.

rotate

Whether to rotate added images for less atlas size.

minSize

Min size of atlas.

maxSize

Max size of atlas.

Variables

@:value(false)read onlyallowRotation:Bool = false

Whether to allow image rotation for packing in atlas.

bitmapData:BitmapData

BitmapData of this atlas, combines all images into a big one.

@:value(1)read onlyborder:Int = 1

Offsets between nodes.

read onlygraphic:FlxGraphic

Graphic for this atlas.

@:isVarheight:Int

Total height of the atlas.

@:value(1024)maxHeight:Int = 1024

Maximum height for this atlas.

@:value(1024)maxWidth:Int = 1024

Maximum width for this atlas.

@:value(128)minHeight:Int = 128

Minimum height for this atlas

@:value(128)minWidth:Int = 128

Minimum width for this atlas.

read onlyname:String

Name of this atlas, used as a key in the bitmap cache.

read onlynodes:Map<String, FlxNode>

@:value(false)persist:Bool = false

Whether this atlas should stay in memory after state switch. Default value if false.

@:value(false)powerOfTwo:Bool = false

Whether the size of this atlas should be the power of 2 or not.

read onlyroot:FlxNode

Root node of the atlas.

@:isVarwidth:Int

Total width of the atlas.

Methods

addNode(Graphic:FlxGraphicSource, ?Key:String):FlxNode

Adds a new node to the atlas.

Parameters:

Graphic

Image to store. Could be a BitmapData, String (key from OpenFL's asset cache) or a Class<Dynamic>.

Key

Image name, optional. You can omit it if you pass String or Class<Dynamic> as a Graphic source.

Returns:

Newly created and added node, or null if there is no space for it.

addNodeWithSpacesAndBorders(Graphic:FlxGraphicSource, ?Key:String, tileSize:FlxPoint, tileSpacing:FlxPoint, ?tileBorder:FlxPoint, ?region:FlxRect):FlxTileFrames

Generates a new BitmapData with spaces between tiles, adds this BitmapData to this atlas, generates a FlxTileFrames object for the added node and returns it. Can be useful for tilemaps.

Parameters:

Graphic

Source image for node, where spaces will be inserted (could be a BitmapData, String or Class<Dynamic>).

Key

Optional key for image

tileSize

The size of tile in spritesheet

tileSpacing

Offsets to add in spritesheet between tiles

tileBorder

Border to add around tiles (helps to avoid "tearing" problem)

region

Region of source image to use as a source graphic

Returns:

Generated FlxTileFrames for the added node

addNodes(bitmaps:Array<BitmapData>, keys:Array<String>):FlxAtlas

Optimized version of method for adding multiple nodes to atlas. Uses less of the atlas' area (it sorts images by the size before adding them to atlas).

Parameters:

bitmaps

BitmapData's to insert

keys

Names of these BitmapData objects.

Returns:

addToQueue(data:BitmapData, key:String):FlxAtlas

Adds new object to queue for later creation of new node

Parameters:

data

BitmapData to bake on atlas

key

"name" of the BitmapData. You'll use it as a key for accessing the created node.

clear():Void

Clears all data in atlas. Use it when you want reuse this atlas. WARNING: it will destroy the graphic of this image, so you can get null pointer exceptions if you're still using it for your sprites.

createQueue():FlxAtlas

Creates a new "queue" for adding new nodes. This method should be used with the addToQueue() and generateFromQueue() methods: - first, you create queue, like atlas.createQueue(); - second, you add several bitmaps to the queue: atlas.addToQueue(bmd1, "key1").addToQueue(bmd2, "key2"); - third, you actually bake those bitmaps onto the atlas: atlas.generateFromQueue();

destroy():Void

Destroys the atlas. Use only if you want to clear memory and don't need this atlas anymore, since it disposes the BitmapData and removes it from the cache.

generateFromQueue():FlxAtlas

Adds all objects in "queue" to existing atlas. Doesn't remove any nodes.

@:has_untypedgetAtlasFrames():FlxAtlasFrames

Gets the FlxAtlasFrames object for this atlas. It caches graphic of this atlas and generates FlxAtlasFrames if it doesn't exist yet.

Returns:

FlxAtlasFrames for this atlas

@:has_untypedgetLibGdxData():String

Returns atlas data in LibGdx packer format.

getNode(key:String):FlxNode

Gets a node by it's name.

Parameters:

key

Node name to search for.

Returns:

node with searched name. null if atlas doesn't contain any node with that name.

hasNodeWithName(nodeName:String):Bool

Checks if the atlas already contains node with the same name.

Parameters:

nodeName

Node name to check.

Returns:

true if atlas already contains node with the name.