The TileContainer type is a special kind of Tile that can hold other tiles within it.

Tile and TileContainer objects can be rendered by adding them to a Tilemap instance.

Constructor

@:value({ originY : 0, originX : 0, rotation : 0, scaleY : 1, scaleX : 1, y : 0, x : 0 })new(x:Float = 0, y:Float = 0, scaleX:Float = 1, scaleY:Float = 1, rotation:Float = 0, originX:Float = 0, originY:Float = 0)

Variables

read onlynumTiles:Int

Returns the number of tiles of this object.

Methods

addTile(tile:Tile):Tile

Adds a Tile instance to this TileContainer instance. The tile is added to the front (top) of all other tiles in this TileContainer instance. (To add a tile to a specific index position, use the addTileAt() method.)

Parameters:

tile

The Tile instance to add to this TileContainer instance.

Returns:

The Tile instance that you pass in the tile parameter.

addTileAt(tile:Tile, index:Int):Tile

Adds a Tile instance to this TileContainer instance. The tile is added at the index position specified. An index of 0 represents the back (bottom) of the rendered list for this TileContainer object.

For example, the following example shows three tiles, labeled a, b, and c, at index positions 0, 2, and 1, respectively:

b over c over a

Parameters:

tile

The Tile instance to add to this TileContainer instance.

index

The index position to which the tile is added. If you specify a currently occupied index position, the tile object that exists at that position and all higher positions are moved up one position in the tile list.

Returns:

The Tile instance that you pass in the tile parameter.

addTiles(tiles:Array<Tile>):Array<Tile>

Adds an Array of Tile instances to this TileContainer instance. The tiles are added to the front (top) of all other tiles in this TileContainer instance.

Parameters:

tiles

The Tile instances to add to this TileContainer instance.

Returns:

The Tile Array that you pass in the tiles parameter.

contains(tile:Tile):Bool

Determines whether the specified tile is contained within the TileContainer instance. The search includes the entire tile list including this TileContainer instance. Grandchildren, great-grandchildren, and so on each return true.

Parameters:

tile

The tile object to test.

Returns:

true if the tile object is contained within the TileContainer; otherwise false.

getBounds(targetCoordinateSpace:Tile):Rectangle

Override from tile. A single tile, just has his rectangle. A container must get a rectangle that contains all other rectangles.

Parameters:

targetCoordinateSpace

The tile that works as a coordinate system.

Returns:

Rectangle The bounding box. If no box found, this will return {0,0,0,0} rectangle instead of null.

getTileAt(index:Int):Tile

Returns the tile instance that exists at the specified index.

Parameters:

index

The index position of the tile object.

Returns:

The tile object at the specified index position.

getTileIndex(tile:Tile):Int

Returns the index position of a contained Tile instance.

Parameters:

child

The Tile instance to identify.

Returns:

The index position of the tile object to identify.

removeTile(tile:Tile):Tile

Removes the specified Tile instance from the tile list of the TileContainer instance. The index positions of any tile objects above the tile in the TileContainer are decreased by 1.

Parameters:

tile

The Tile instance to remove.

Returns:

The Tile instance that you pass in the tile parameter.

removeTileAt(index:Int):Tile

Removes a Tile from the specified index position in the tile list of the TileContainer. The index positions of any tile objects above the tile in the TileContainer are decreased by 1.

Parameters:

index

The index of the Tile to remove.

Returns:

The Tile instance that was removed.

@:value({ endIndex : 0x7fffffff, beginIndex : 0 })removeTiles(beginIndex:Int = 0, endIndex:Int = 0x7fffffff):Void

Removes all Tile instances from the tile list of the TileContainer instance.

Parameters:

beginIndex

The beginning position.

endIndex

The ending position.

setTileIndex(tile:Tile, index:Int):Void

Changes the position of an existing tile in the tile container. This affects the layering of tile objects. For example, the following example shows three tile objects, labeled a, b, and c, at index positions 0, 1, and 2, respectively:

c over b over a

When you use the setTileIndex() method and specify an index position that is already occupied, the only positions that change are those in between the tile object's former and new position. All others will stay the same. If a tile is moved to an index LOWER than its current index, all tiles in between will INCREASE by 1 for their index reference. If a tile is moved to an index HIGHER than its current index, all tiles in between will DECREASE by 1 for their index reference. For example, if the tile container in the previous example is named container, you can swap the position of the tile objects labeled a and b by calling the following code:

container.setTileIndex(container.getTileAt(1), 0);

This code results in the following arrangement of objects:

c over a over b

Parameters:

tile

The Tile instance for which you want to change the index number.

index

The resulting index number for the tile object.

sortTiles(compareFunction:(Tile, Tile) ‑> Int):Void

Sorts the z-order (front-to-back order) of all the tile objects in this container based on a comparison function.

A comparison function should take two arguments to compare. Given the elements A and B, the result of compareFunction can have a negative, 0, or positive value:

  • A negative return value specifies that A appears before B in the sorted sequence.
  • A return value of 0 specifies that A and B have the same sort order.
  • A positive return value specifies that A appears after B in the sorted sequence.

The sort operation is not guaranteed to be stable, which means that the order of equal elements may not be retained.

Parameters:

compareFunction

A comparison function to use when sorting.

swapTiles(tile1:Tile, tile2:Tile):Void

Swaps the z-order (front-to-back order) of the two specified tile objects. All other tile objects in the tile container remain in the same index positions.

Parameters:

child1

The first tile object.

child2

The second tile object.

swapTilesAt(index1:Int, index2:Int):Void

Swaps the z-order (front-to-back order) of the tile objects at the two specified index positions in the tile list. All other tile objects in the tile container remain in the same index positions.

Parameters:

index1

The index position of the first tile object.

index2

The index position of the second tile object.

Inherited Variables

Defined by Tile

@:keepalpha:Float

Indicates the alpha transparency value of the object specified. Valid values are 0 (fully transparent) to 1 (fully opaque). The default value is 1. Tile objects with alpha set to 0 are active, even though they are invisible.

blendMode:BlendMode

A value from the BlendMode class that specifies which blend mode to use.

This property is supported only when using hardware rendering or the Flash target.

@:betacolorTransform:ColorTransform

A ColorTransform object containing values that universally adjust the colors in the display object.

This property is supported only when using hardware rendering.

@SuppressWarnings("checkstyle:Dynamic")data:Dynamic

An additional field for custom user-data

@:keepheight:Float

Indicates the height of the tile, in pixels. The height is calculated based on the bounds of the tile after local transformations. When you set the height property, the scaleY property is adjusted accordingly. If a tile has a height of zero, no change is applied

id:Int

The ID of the tile to draw from the Tileset

matrix:Matrix

A Matrix object containing values that alter the scaling, rotation, and translation of the tile object.

If the matrix property is set to a value (not null), the x, y, scaleX, scaleY and the rotation values will be overwritten.

@:keeporiginX:Float

Modifies the origin x coordinate for this tile, which is the center value used when determining position, scale and rotation.

@:keeporiginY:Float

Modifies the origin y coordinate for this tile, which is the center value used when determining position, scale and rotation.

read onlyparent:TileContainer

Indicates the ITileContainer object that contains this display object. Use the parent property to specify a relative path to tile objects that are above the current tile object in the tile list hierarchy.

rect:Rectangle

The custom rectangle to draw from the Tileset

@:keeprotation:Float

Indicates the rotation of the Tile instance, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement tile.rotation = 450 is the same as tile.rotation = 90.

@:keepscaleX:Float

Indicates the horizontal scale (percentage) of the object as applied from the origin point. The default origin point is (0,0). 1.0 equals 100% scale.

Scaling the local coordinate system changes the x and y property values, which are defined in whole pixels.

@:keepscaleY:Float

Indicates the vertical scale (percentage) of an object as applied from the origin point of the object. The default origin point is (0,0). 1.0 is 100% scale.

Scaling the local coordinate system changes the x and y property values, which are defined in whole pixels.

@:betashader:Shader

Uses a custom Shader instance when rendering this tile.

This property is only supported when using hardware rendering.

tileset:Tileset

The Tileset that this Tile is rendered from.

If null, this Tile will use the Tileset value of its parent.

visible:Bool

Whether or not the tile object is visible.

@:keepwidth:Float

Indicates the width of the tile, in pixels. The width is calculated based on the bounds of the tile after local transformations. When you set the width property, the scaleX property is adjusted accordingly. If a tile has a width of zero, no change is applied

@:keepx:Float

Indicates the x coordinate of the Tile instance relative to the local coordinates of the parent ITileContainer. If the object is inside a TileContainer that has transformations, it is in the local coordinate system of the enclosing TileContainer. Thus, for a TileContainer rotated 90° counterclockwise, the TileContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.

@:keepy:Float

Indicates the y coordinate of the Tile instance relative to the local coordinates of the parent ITileContainer. If the object is inside a TileContainer that has transformations, it is in the local coordinate system of the enclosing TileContainer. Thus, for a TileContainer rotated 90° counterclockwise, the TileContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.

Inherited Methods

Defined by Tile

hitTestTile(obj:Tile):Bool

Evaluates the bounding box of the tile to see if it overlaps or intersects with the bounding box of the obj tile. Both tiles must be under the same Tilemap for this to work.

Parameters:

obj

The tile to test against.

Returns:

true if the bounding boxes of the tiles intersect; false if not.

invalidate():Void

Calling the invalidate() method signals to have the current tile redrawn the next time the tile object is eligible to be rendered.

Invalidation is handled automatically, but in some cases it is necessary to trigger it manually, such as changing the parameters of a Shader instance attached to this tile.