The Tileset class lets you specify logical rectangles within a larger BitmapData object, to be rendered using a Tilemap instance.

The Tileset() constructor allows you to create a Tileset object that contains a reference to a BitmapData object. After you create a Tileset object, use the addRect() method to specify rectangles to be used for tile rendering.

Constructor

@:value({ rects : null })new(bitmapData:BitmapData, ?rects:Array<Rectangle>)

Creates a new Tileset instance.

Parameters:

bitmapData

A BitmapData object to reference

rects

An optional array of rectangles to define with the referenced BitmapData

Variables

bitmapData:BitmapData

The BitmapData object being referenced.

read onlynumRects:Int

Returns the number of rectangles defined in this Tileset.

rectData:Vector<Float>

The rectangles contained in this Tileset, structured as a Vector object.

You can use the Tileset rectData property alongside the Graphics drawQuads method as a convenient way of re-using a list of rectangles.

Methods

addRect(rect:Rectangle):Int

Adds a new rectangle to this Tilemap object.

Parameters:

rect

A Rectangle represented a part of the referenced BitmapData object

Returns:

The assigned ID value for this new rectangle

clone():Tileset

Duplicates an instance of a Tileset subclass.

Returns:

A new Tileset object that is identical to the original.

getRect(id:Int):Rectangle

Get the rectangle value associated with a specific tile ID.

If the ID is invalid, then a null value will be returned.

Parameters:

id

A tile ID

Returns:

A new Rectangle containing the tile source rectangle, or null if the tile ID does not exist in this Tileset

getRectID(rect:Rectangle):Null<Int>

Gets the tile ID associated with a specified rectangle value, if it is defined in the Tileset. This will return null if the rectangle value is not defined in the Tileset.

Parameters:

rect

A Rectangle object to compare against

Returns:

The defined tile ID, or null if the rectangle value is not present in this Tileset

hasRect(rect:Rectangle):Bool

Returns whether the current Tileset already has a rectangle defined that matches the dimensions of a specific rectangle object.

Parameters:

rect

A Rectangle object to compare against

Returns:

Whether the Tileset already contains the value of this rectangle