Spritesheet frame collection. It is used for tilemaps and animated sprites.

Variables

@:value(0)numCols:Int = 0

@:value(0)numRows:Int = 0

tileSize:FlxPoint

The size of frame in this spritesheet.

Methods

equals(tileSize:FlxPoint, ?region:FlxRect, ?atlasFrame:FlxFrame, ?tileSpacing:FlxPoint, ?border:FlxPoint):Bool

TileFrames comparison method. For internal use.

inlinegetByTilePosition(column:Int, row:Int):FlxFrame

Gets frame by its "position" in spritesheet.

Static methods

staticcombineTileFrames(tileframes:Array<FlxTileFrames>, ?spacing:FlxPoint, ?border:FlxPoint):FlxTileFrames

This method takes array of tile frames collections and then combine them in one big tileset. The order of bitmaps in array is important.

var combinedFrames = FlxTileFrames.combineTileFrames(tileframes);
tilemap.loadMapFromCSV(mapData, combinedFrames);

or

sprite.frames = combinedFrames;

Parameters:

tileframes

Tile frames collection to combine tiles from.

Returns:

Atlas frames collection, which you can load in tilemaps or sprites:

staticcombineTileSets(bitmaps:Array<BitmapData>, tileSize:FlxPoint, ?spacing:FlxPoint, ?border:FlxPoint):FlxTileFrames

This method takes array of tileset bitmaps and the size of tiles in them and then combine them in one big tileset. The order of bitmaps in the array is important.

var combinedFrames = FlxTileFrames.combineTileSets(bitmaps, FlxPoint.get(16, 16));
tilemap.loadMapFromCSV(mapData, combinedFrames);

or

sprite.frames = combinedFrames;

Parameters:

bitmaps

tilesets

tileSize

The size of tiles (tilesets should have tiles of the same size).

Returns:

Atlas frames collection, which you can load in tilemaps or sprites:

staticfindFrame(graphic:FlxGraphic, tileSize:FlxPoint, ?region:FlxRect, ?atlasFrame:FlxFrame, ?tileSpacing:FlxPoint, ?border:FlxPoint):FlxTileFrames

Searches FlxTileFrames object for a specified FlxGraphic object which has the same parameters (frame size, frame spacings, region of image, etc.).

Parameters:

graphic

FlxGraphic object to search FlxTileFrames for.

tileSize

The size of tiles in TileFrames.

region

The region of source image used for spritesheet generation.

atlasFrame

Optional FlxFrame object used for spritesheet generation.

tileSpacing

Spaces between tiles in spritesheet.

Returns:

FlxTileFrames object which corresponds to specified arguments. Could be null if there is no such FlxTileFrames.

staticfromAtlasByPrefix(Frames:FlxAtlasFrames, Prefix:String):FlxTileFrames

Creates new a FlxTileFrames collection from atlas frames which begin with a common name (e.g. "tiles-") and differ in indices (e.g. "001", "002", etc.). This method is similar to FlxAnimationController's addByPrefix().

Parameters:

Frames

Collection of atlas frames to generate tiles from.

Prefix

Common beginning of image names in atlas (e.g. "tiles-").

Returns:

Generated tile frames collection.

staticfromBitmapAddSpacesAndBorders(source:FlxGraphicAsset, tileSize:FlxPoint, ?tileSpacing:FlxPoint, ?tileBorder:FlxPoint, ?region:FlxRect):FlxTileFrames

Gets source BitmapData, generates new BitmapData with spaces between frames (if there is no such BitmapData in the cache already) and creates FlxTileFrames collection.

Parameters:

source

The source of graphic for frame collection.

tileSize

The size of tiles in spritesheet.

tileSpacing

Desired offsets between frames in spritesheet (this method takes spritesheet bitmap without offsets between frames and adds them).

tileBorder

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

region

Region of image to generate spritesheet from. Default value is null, which means that the whole image will be used for spritesheet generation.

Returns:

Newly created spritesheet.

staticfromFrame(frame:FlxFrame, tileSize:FlxPoint, ?tileSpacing:FlxPoint):FlxTileFrames

Generates spritesheet frame collection from provided frame. Can be useful for spritesheets packed into atlases. It can generate spritesheets from rotated and cropped frames also, which is important for devices with limited memory.

Parameters:

frame

Frame, containing spritesheet image

tileSize

The size of tiles in spritesheet

tileSpacing

Offsets between frames in spritesheet. Default value is null, which means no offsets between tiles.

Returns:

Newly created spritesheet frame collection.

staticfromFrameAddSpacesAndBorders(frame:FlxFrame, tileSize:FlxPoint, ?tileSpacing:FlxPoint, ?tileBorder:FlxPoint):FlxTileFrames

Gets FlxFrame object, generates new BitmapData with spaces between tiles in the frame (if there is no such BitmapData in the cache already) and creates a FlxTileFrames collection.

Parameters:

frame

Frame to generate tiles from.

tileSize

the size of tiles in spritesheet.

tileSpacing

desired offsets between frames in spritesheet. (this method takes spritesheet bitmap without offsets between frames and adds them).

tileBorder

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

Returns:

Newly created spritesheet.

staticfromFrames(Frames:Array<FlxFrame>):FlxTileFrames

Just generates tile frames collection from specified array of frames.

Parameters:

Frames

Array of frames to generate tile frames from. They all should have the same source size and parent graphic. If not then null will be returned.

Returns:

Generated collection of frames.

staticfromGraphic(graphic:FlxGraphic, tileSize:FlxPoint, ?region:FlxRect, ?tileSpacing:FlxPoint):FlxTileFrames

Generates spritesheet frame collection from provided region of image.

Parameters:

graphic

Source graphic for spritesheet.

tileSize

The size of tiles in spritesheet.

region

Region of image to use for spritesheet generation. Default value is null, which means that the whole image will be used for it.

tileSpacing

Offsets between frames in spritesheet. Default value is null, which means no offsets between tiles.

Returns:

Newly created spritesheet frame collection.

staticfromRectangle(source:FlxGraphicAsset, tileSize:FlxPoint, ?region:FlxRect, ?tileSpacing:FlxPoint):FlxTileFrames

Generates a spritesheet frame collection from the provided image region.

Parameters:

source

Source graphic for the spritesheet.

tileSize

The size of tiles in spritesheet.

region

Region of image to use for spritesheet generation. Default value is null, which means that whole image will be used for it.

tileSpacing

Offsets between frames in spritesheet. Default value is null, which means no offsets between tiles.

Returns:

Newly created spritesheet frame collection.

Inherited Variables

Defined by FlxFramesCollection

read onlyborder:FlxPoint

How much space was trimmed around the original frames. Use addBorder() to add borders.

frames:Array<FlxFrame>

Array with all frames of this collection.

framesHash:Map<String, FlxFrame>

Hash of frames for this frame collection. Used only in FlxAtlasFrames and FlxBitmapFont (not implemented yet), but you can try to use it for other types of collections (give names to your frames).

read onlynumFrames:Int

Number of frames in this collection.

parent:FlxGraphic

Graphic object this frames belongs to.

read onlytype:FlxFrameCollectionType

Type of this frame collection. Used for faster type detection (less casting).

Inherited Methods

Defined by FlxFramesCollection

@:value({ flipY : false, flipX : false, angle : 0 })addAtlasFrame(frame:FlxRect, sourceSize:FlxPoint, offset:FlxPoint, ?name:String, angle:FlxFrameAngle = 0, flipX:Bool = false, flipY:Bool = false):FlxFrame

Adds new frame to this frame collection. This method runs additional check, and can add rotated frames (from texture atlases).

Parameters:

frame

Region of image.

sourceSize

Original size of packed image (if image had been cropped, then original size will be bigger than frame size).

offset

How frame region is located on original frame image (offset from top left corner of original image).

name

Name for this frame (name of packed image file).

angle

Rotation of packed image (can be 0, 90 or -90).

flipX

If packed image should be horizontally flipped.

flipY

If packed image should be vertically flipped.

Returns:

Newly created and added frame object.

addEmptyFrame(size:FlxRect):FlxFrame

Adds empty frame into this frame collection. An empty frame is doing almost nothing for all the time.

Parameters:

size

Dimensions of the frame to add.

Returns:

Newly added empty frame.

addSpriteSheetFrame(region:FlxRect):FlxFrame

Adds new regular (not rotated) FlxFrame to this frame collection.

Parameters:

region

Region of image which new frame will display.

Returns:

Newly created FlxFrame object for specified region of image.

inlinegetByIndex(index:Int):FlxFrame

Finds frame in frames array by its index.

Parameters:

index

Index of the frame in the frames array.

Returns:

Frame with specified index in this frames collection (if there is one).

inlinegetByName(name:String):FlxFrame

Finds a frame in framesHash by its name.

Parameters:

name

The name of the frame to find.

Returns:

Frame with specified name (if there is one).

inlinegetFrameIndex(frame:FlxFrame):Int

Finds the index of the specified frame in the frames array.

Parameters:

frame

Frame to find.

Returns:

Index of the specified frame.

getIndexByName(name:String):Int

Finds frame index by its name.

Parameters:

name

Name of the frame.

Returns:

Index of the frame with specified name.

pushFrame(frameObj:FlxFrame):FlxFrame

Helper method for a adding frame to the collection.

Parameters:

frameObj

Frame to add.

Returns:

Added frame.