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
Constructor
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 |
---|---|
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
Methods
addNode(Graphic:FlxGraphicSource, ?Key:String):FlxNode
Adds a new node to the atlas.
Parameters:
Graphic | Image to store. Could be a |
---|---|
Key | Image name, optional.
You can omit it if you pass |
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 |
---|---|
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 |
|
---|---|
keys | Names of these |
Returns:
this
FlxAtlas
addToQueue(data:BitmapData, key:String):FlxAtlas
Adds new object to queue for later creation of new node
Parameters:
data |
|
---|---|
key | "name" of the |
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.
getAtlasFrames():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
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.