class FlxBaseTilemap<Tile>
package flixel.tile
extends FlxObject › FlxBasic
extended by FlxTypedTilemap
Variables
auto:FlxTilemapAutoTiling = OFF
Set this flag to use one of the 16-tile binary auto-tile algorithms (OFF, AUTO, or ALT).
customTileRemap:Array<Int>
Set this to create your own image index remapper, so you can create your own tile layouts. Mostly useful in combination with the auto-tilers.
Normally, each tile's value in _data corresponds to the index of a tile frame in the tilesheet. With this active, each value in _data is a lookup value to that index in customTileRemap.
Example: customTileRemap = [10,9,8,7,6] means: 0=10, 1=9, 2=8, 3=7, 4=6
Methods
calcRayEntry(start:FlxPoint, end:FlxPoint, ?result:FlxPoint):Null<FlxPoint>
Calculates at which point where the given line, from start to end, first enters the tilemap. If the line starts inside the tilemap, a copy of start is returned. If the line never enters the tilemap, null is returned.
Note: If a result vector is supplied and the line is outside the tilemap, null is returned and the supplied result is unchanged
Parameters:
start | The start of the line |
---|---|
end | The end of the line |
result | Optional result vector, to avoid creating a new instance to be returned. Only returned if the line enters the tilemap. |
Returns:
The point of entry of the line into the tilemap, if possible.
5.0.0
.inlinecalcRayExit(start:FlxPoint, end:FlxPoint, ?result:FlxPoint):Null<FlxPoint>
Calculates at which point where the given line, from start to end, was last inside the tilemap. If the line ends inside the tilemap, a copy of end is returned. If the line is never inside the tilemap, null is returned.
Note: If a result vector is supplied and the line is outside the tilemap, null is returned and the supplied result is unchanged
Parameters:
start | The start of the line |
---|---|
end | The end of the line |
result | Optional result vector, to avoid creating a new instance to be returned. Only returned if the line enters the tilemap. |
Returns:
The point of exit of the line from the tilemap, if possible.
5.0.0
.computePathData(startIndex:Int, endIndex:Int, diagonalPolicy:FlxTilemapDiagonalPolicy = WIDE, stopOnEnd:Bool = true):FlxPathfinderData
Pathfinding helper function, floods a grid with distance information until it finds the end point. NOTE: Currently this process does NOT use any kind of fancy heuristic! It's pretty brute.
Parameters:
startIndex | The starting tile's map index. |
---|---|
endIndex | The ending tile's map index. |
policy | Decides how to move and evaluate the paths for comparison. |
stopOnEnd | Whether to stop at the end or not (default true) |
Returns:
An array of FlxPoint nodes. If the end tile could not be found, then a null Array is returned instead.
5.0.0
.computePathDistance(startIndex:Int, endIndex:Int, diagonalPolicy:FlxTilemapDiagonalPolicy = WIDE, stopOnEnd:Bool = true):Array<Int>
Pathfinding helper function, floods a grid with distance information until it finds the end point. NOTE: Currently this process does NOT use any kind of fancy heuristic! It's pretty brute.
Parameters:
startIndex | The starting tile's map index. |
---|---|
endIndex | The ending tile's map index. |
diagonalPolicy | How to treat diagonal movement. |
stopOnEnd | Whether to stop at the end or not (default true) |
Returns:
An array of FlxPoint nodes. If the end tile could not be found, then a null Array is returned instead.
inlinefindPath(start:FlxPoint, end:FlxPoint, simplify:FlxPathSimplifier = LINE, diagonalPolicy:FlxTilemapDiagonalPolicy = WIDE):Array<FlxPoint>
Find a path through the tilemap. Any tile with any collision flags set is treated as impassable. If no path is discovered then a null reference is returned.
Parameters:
start | The start point in world coordinates. |
---|---|
end | The end point in world coordinates. |
simplify | Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line. Default value is true. |
raySimplify | Whether to run an extra raycasting simplification algorithm over the remaining path data. This can result in some close corners being cut, and should be used with care if at all (yet). Default value is false. |
diagonalPolicy | How to treat diagonal movement. (Default is WIDE, count +1 tile for diagonal movement) |
Returns:
An Array of FlxPoints, containing all waypoints from the start to the end. If no path could be found, then a null reference is returned.
inlinefindPathCustom(pathfinder:FlxPathfinder, start:FlxPoint, end:FlxPoint, simplify:FlxPathSimplifier = LINE):Array<FlxPoint>
Find a path through the tilemap. Any tile with any collision flags set is treated as impassable. If no path is discovered then a null reference is returned.
Parameters:
pathfinder | Decides how to move and evaluate the paths for comparison. |
---|---|
start | The start point in world coordinates. |
end | The end point in world coordinates. |
simplify | Whether to run a basic simplification algorithm over the path data, removing extra points that are on the same line. Default value is true. |
raySimplify | Whether to run an extra raycasting simplification algorithm over the remaining path data. This can result in some close corners being cut, and should be used with care if at all (yet). Default value is false. |
Returns:
An Array of FlxPoints, containing all waypoints from the start to the end. If no path could be found, then a null reference is returned.
5.0.0
.getBounds(?bounds:FlxRect):FlxRect
Get the world coordinates and size of the entire tilemap as a FlxRect.
Parameters:
bounds | Optional, pass in a pre-existing FlxRect to prevent instantiation of a new object. |
---|
Returns:
A FlxRect containing the world coordinates and size of the entire tilemap.
getData(simple:Bool = false):Array<Int>
Fetches the tilemap data array.
Parameters:
simple | If true, returns the data as copy, as a series of 1s and 0s (useful for auto-tiling stuff). Default value is false, meaning it will return the actual data array (NOT a copy). |
---|
Returns:
An array the size of the tilemap full of integers indicating tile placement.
getTile(x:Int, y:Int):Int
Check the value of a particular tile.
Parameters:
x | The X coordinate of the tile (in tiles, not pixels). |
---|---|
y | The Y coordinate of the tile (in tiles, not pixels). |
Returns:
An integer containing the value of the tile at this spot in the array.
getTileByIndex(index:Int):Int
Get the value of a tile in the tilemap by index.
Parameters:
index | The slot in the data array (Y * widthInTiles + X) where this tile is stored. |
---|
Returns:
An integer containing the value of the tile at this spot in the array.
getTileCollisions(index:Int):FlxDirectionFlags
Gets the collision flags of tile by index.
Parameters:
index | Tile index returned by getTile or getTileByIndex |
---|
Returns:
The internal collision flag for the requested tile.
getTileInstances(index:Int):Array<Int>
Returns a new array full of every map index of the requested tile type.
Parameters:
index | The requested tile type. |
---|
Returns:
An Array with a list of all map indices of that tile type.
loadMapFrom2DArray(mapData:Array<Array<Int>>, tileGraphic:FlxTilemapGraphicAsset, tileWidth:Int = 0, tileHeight:Int = 0, ?autoTile:FlxTilemapAutoTiling, startingIndex:Int = 0, drawIndex:Int = 1, collideIndex:Int = 1):FlxBaseTilemap<Tile>
Load the tilemap with string data and a tile graphic.
Parameters:
mapData | A 2D array containing the (non-negative) tile indices. The length of the inner arrays should be consistent. |
---|---|
tileGraphic | All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. |
tileWidth | The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. |
tileHeight | The height of your tiles (e.g. 8) - defaults to width if unspecified. |
autoTile | Whether to load the map using an automatic tile placement algorithm (requires 16 tiles!). Setting this to either AUTO or ALT will override any values you put for StartingIndex, DrawIndex, or CollideIndex. |
startingIndex | Used to sort of insert empty tiles in front of the provided graphic. Default is 0, usually safest ot leave it at that. Ignored if AutoTile is set. |
drawIndex | Initializes all tile objects equal to and after this index as visible. Default value is 1. Ignored if AutoTile is set. |
collideIndex | Initializes all tile objects equal to and after this index as allowCollisions = ANY. Default value is 1. Ignored if AutoTile is set. Can override and customize per-tile-type collision behavior using setTileProperties(). |
Returns:
A reference to this instance of FlxTilemap, for chaining as usual :)
loadMapFromArray(mapData:Array<Int>, widthInTiles:Int, heightInTiles:Int, tileGraphic:FlxTilemapGraphicAsset, tileWidth:Int = 0, tileHeight:Int = 0, ?autoTile:FlxTilemapAutoTiling, startingIndex:Int = 0, drawIndex:Int = 1, collideIndex:Int = 1):FlxBaseTilemap<Tile>
Load the tilemap with string data and a tile graphic.
Parameters:
mapData | An array containing the (non-negative) tile indices. |
---|---|
widthInTiles | The width of the tilemap in tiles |
heightInTiles | The height of the tilemap in tiles |
tileGraphic | All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. |
tileWidth | The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. |
tileHeight | The height of your tiles (e.g. 8) - defaults to width if unspecified. |
autoTile | Whether to load the map using an automatic tile placement algorithm (requires 16 tiles!). Setting this to either AUTO or ALT will override any values you put for StartingIndex, DrawIndex, or CollideIndex. |
startingIndex | Used to sort of insert empty tiles in front of the provided graphic. Default is 0, usually safest ot leave it at that. Ignored if AutoTile is set. |
drawIndex | Initializes all tile objects equal to and after this index as visible. Default value is 1. Ignored if AutoTile is set. |
collideIndex | Initializes all tile objects equal to and after this index as allowCollisions = ANY. Default value is 1. Ignored if AutoTile is set. Can override and customize per-tile-type collision behavior using setTileProperties(). |
Returns:
A reference to this instance of FlxTilemap, for chaining as usual :)
loadMapFromCSV(mapData:String, tileGraphic:FlxTilemapGraphicAsset, tileWidth:Int = 0, tileHeight:Int = 0, ?autoTile:FlxTilemapAutoTiling, startingIndex:Int = 0, drawIndex:Int = 1, collideIndex:Int = 1):FlxBaseTilemap<Tile>
Load the tilemap with string data and a tile graphic.
Parameters:
mapData | A csv-formatted string indicating what order the tiles should go in (or the path to that file) |
---|---|
tileGraphic | All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. |
tileWidth | The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. |
tileHeight | The height of your tiles (e.g. 8) - defaults to width if unspecified. |
autoTile | Whether to load the map using an automatic tile placement algorithm (requires 16 tiles!). Setting this to either AUTO or ALT will override any values you put for StartingIndex, DrawIndex, or CollideIndex. |
startingIndex | Used to sort of insert empty tiles in front of the provided graphic. Default is 0, usually safest ot leave it at that. Ignored if AutoTile is set. |
drawIndex | Initializes all tile objects equal to and after this index as visible. Default value is 1. Ignored if AutoTile is set. |
collideIndex | Initializes all tile objects equal to and after this index as allowCollisions = ANY. Default value is 1. Ignored if AutoTile is set. Can override and customize per-tile-type collision behavior using setTileProperties(). |
Returns:
A reference to this instance of FlxTilemap, for chaining as usual :)
loadMapFromGraphic(mapGraphic:FlxGraphicSource, invert:Bool = false, scale:Int = 1, ?colorMap:Array<FlxColor>, tileGraphic:FlxTilemapGraphicAsset, tileWidth:Int = 0, tileHeight:Int = 0, ?autoTile:FlxTilemapAutoTiling, startingIndex:Int = 0, drawIndex:Int = 1, collideIndex:Int = 1):FlxBaseTilemap<Tile>
Load the tilemap with image data and a tile graphic. Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK.
Parameters:
mapGraphic | The image you want to use as a source of map data, where each pixel is a tile (or more than one tile if you change Scale's default value). Preferably black and white. |
---|---|
invert | Load white pixels as solid instead. |
scale | Default is 1. Scale of 2 means each pixel forms a 2x2 block of tiles, and so on. |
colorMap | An array of color values (alpha values are ignored) in the order they're intended to be assigned as indices |
tileGraphic | All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData. |
tileWidth | The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified. |
tileHeight | The height of your tiles (e.g. 8) - defaults to width if unspecified. |
autoTile | Whether to load the map using an automatic tile placement algorithm (requires 16 tiles!). Setting this to either AUTO or ALT will override any values you put for StartingIndex, DrawIndex, or CollideIndex. |
startingIndex | Used to sort of insert empty tiles in front of the provided graphic. Default is 0, usually safest ot leave it at that. Ignored if AutoTile is set. |
drawIndex | Initializes all tile objects equal to and after this index as visible. Default value is 1. Ignored if AutoTile is set. |
collideIndex | Initializes all tile objects equal to and after this index as allowCollisions = ANY. Default value is 1. Ignored if AutoTile is set. Can override and customize per-tile-type collision behavior using setTileProperties(). |
Returns:
A reference to this instance of FlxTilemap, for chaining as usual :)
4.1.0
.overlaps(objectOrGroup:FlxBasic, inScreenSpace:Bool = false, ?camera:FlxCamera):Bool
Checks to see if some FlxObject overlaps this FlxObject object in world space. If the group has a LOT of things in it, it might be faster to use FlxG.overlaps(). WARNING: Currently tilemaps do NOT support screen space overlap checks!
Parameters:
object | The object being tested. |
---|---|
inScreenSpace | Whether to take scroll factors into account when checking for overlap. |
camera | Specify which game camera you want. If null, getScreenPosition() will just grab the first global camera. |
Returns:
Whether or not the two objects overlap.
overlapsAt(x:Float, y:Float, objectOrGroup:FlxBasic, inScreenSpace:Bool = false, ?camera:FlxCamera):Bool
Checks to see if this FlxObject were located at the given position, would it overlap the FlxObject or FlxGroup? This is distinct from overlapsPoint(), which just checks that point, rather than taking the object's size into account. WARNING: Currently tilemaps do NOT support screen space overlap checks!
Parameters:
x | The X position you want to check. Pretends this object (the caller, not the parameter) is located here. |
---|---|
y | The Y position you want to check. Pretends this object (the caller, not the parameter) is located here. |
objectOrGroup | The object or group being tested. |
inScreenSpace | Whether to take scroll factors into account when checking for overlap. Default is false, or "only compare in world space." |
camera | Specify which game camera you want. If null getScreenPosition() will just grab the first global camera. |
Returns:
Whether or not the two objects overlap.
overlapsPoint(worldPoint:FlxPoint, inScreenSpace:Bool = false, ?camera:FlxCamera):Bool
Checks to see if a point in 2D world space overlaps this FlxObject object.
Parameters:
worldPoint | The point in world space you want to check. |
---|---|
inScreenSpace | Whether to take scroll factors into account when checking for overlap. |
camera | Specify which game camera you want. If null getScreenPosition() will just grab the first global camera. |
Returns:
Whether or not the point overlaps this object.
overlapsWithCallback(object:FlxObject, ?callback:(FlxObject, FlxObject) ‑> Bool, flipCallbackParams:Bool = false, ?position:FlxPoint):Bool
ray(start:FlxPoint, end:FlxPoint, ?result:FlxPoint):Bool
Shoots a ray from the start point to the end point.
If/when it passes through a tile, it stores that point and returns false.
Note: In flixel 5.0.0, this was redone, the old method is now rayStep
Parameters:
start | The world coordinates of the start of the ray. |
---|---|
end | The world coordinates of the end of the ray. |
result | Optional result vector, to avoid creating a new instance to be returned. Only returned if the line enters the rect. |
Returns:
Returns true if the ray made it from Start to End without hitting anything. Returns false and fills Result if a tile was hit.
rayStep(start:FlxPoint, end:FlxPoint, ?result:FlxPoint, resolution:Float = 1):Bool
Shoots a ray from the start point to the end point.
If/when it passes through a tile, it stores that point and returns false.
This method checks at steps and can miss, for better results use ray()
Parameters:
start | The world coordinates of the start of the ray. |
---|---|
end | The world coordinates of the end of the ray. |
result | Optional result vector, to avoid creating a new instance to be returned. Only returned if the line enters the rect. |
resolution | Defaults to 1, meaning check every tile or so. Higher means more checks! |
Returns:
Returns true if the ray made it from Start to End without hitting anything. Returns false and fills Result if a tile was hit.
5.0.0
.setCustomTileMappings(mappings:Array<Int>, ?randomIndices:Array<Int>, ?randomChoices:Array<Array<Int>>, ?randomLambda:() ‑> Float):Void
Set custom tile mapping and/or randomization rules prior to loading. This MUST be called BEFORE loadMap(). WARNING: Using this will cause your maps to take longer to load. Be careful using this in very large tilemaps.
Parameters:
mappings | Array of ints for remapping tiles. Ex: [7,4,12] means "0-->7, 1-->4, 2-->12" |
---|---|
randomIndices | Array of ints indicating which tile indices should be randomized. Ex: [7,4,12] means "replace tile index of 7, 4, or 12 with a randomized value" |
randomChoices | A list of int-arrays that serve as the corresponding choices to randomly choose from. Ex: indices = [7,4], choices = [[1,2],[3,4,5]], 7 will be replaced by either 1 or 2, 4 will be replaced by 3, 4, or 5. |
randomLambda | A custom randomizer function, should return value between 0.0 and 1.0. Initialize your random seed before passing this in! If not defined, will default to unseeded Math.random() calls. |
setTile(x:Int, y:Int, tile:Int, updateGraphics:Bool = true):Bool
Change the data and graphic of a tile in the tilemap.
Parameters:
x | The X coordinate of the tile (in tiles, not pixels). |
---|---|
y | The Y coordinate of the tile (in tiles, not pixels). |
tile | The new integer data you wish to inject. |
updateGraphics | Whether the graphical representation of this tile should change. |
Returns:
Whether or not the tile was actually changed.
setTileByIndex(index:Int, tile:Int, updateGraphics:Bool = true):Bool
Change the data and graphic of a tile in the tilemap.
Parameters:
index | The slot in the data array (Y * widthInTiles + X) where this tile is stored. |
---|---|
tile | The new integer data you wish to inject. |
updateGraphics | Whether the graphical representation of this tile should change. |
Returns:
Whether or not the tile was actually changed.
setTileProperties(tile:Int, allowCollisions:FlxDirectionFlags = ANY, ?callback:(FlxObject, FlxObject) ‑> Void, ?callbackFilter:Class<FlxObject>, range:Int = 1):Void
Adjust collision settings and/or bind a callback function to a range of tiles. This callback function, if present, is triggered by calls to overlap() or overlapsWithCallback().
Parameters:
tile | The tile or tiles you want to adjust. |
---|---|
allowCollisions | Modify the tile or tiles to only allow collisions from certain directions, use FlxObject constants NONE, ANY, LEFT, RIGHT, etc. Default is "ANY". |
callback | The function to trigger, e.g. lavaCallback(Tile:FlxObject, Object:FlxObject). |
callbackFilter | If you only want the callback to go off for certain classes or objects based on a certain class, set that class here. |
range | If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1. |