class flixel.tile.FlxTilemap extends FlxObject

Available on all platforms

This is a traditional tilemap display and collision class. It takes a string of comma-separated numbers and then associates * those values with tiles from the sheet you pass in. It also includes some handy static parsers that can convert * arrays or images into strings that can be loaded.

Class Fields

static var ALT:Int

Better for levels with thick walls that look better with interior corner art.

static var AUTO:Int

Good for levels with thin walls that don'tile need interior corner art.

static var OFF:Int

No auto-tiling.

Instance Fields

var auto:Int

Set this flag to use one of the 16-tile binary auto-tile algorithms (OFF, AUTO, or ALT).

var 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

var heightInTiles:Int

Read-only variable, do NOT recommend changing after the map is loaded!

var region:Region

Rendering variables.

var scale:FlxPoint

Changes the size of this tilemap. Default is (1, 1). * Anything other than the default is very slow with blitting!

var tileScaleHack:Float

Helper variable for non-flash targets. Adjust it's value if you'll see tilemap tearing (empty pixels between tiles). To something like 1.02 or 1.03

var totalTiles:Int

Read-only variable, do NOT recommend changing after the map is loaded!

var widthInTiles:Int

Read-only variable, do NOT recommend changing after the map is loaded!

function new():Void

The tilemap constructor just initializes some basic variables.

function computePathDistance(StartIndex:Int, EndIndex:Int, WideDiagonal:Bool, ?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. * *

StartIndex

The starting tile's map index. *

EndIndex

The ending tile's map index. *

WideDiagonal

Whether to require an additional tile to make diagonal movement. Default value is true. *

StopOnEnd

Whether to stop at the end or not (default true) *

returns

A Flash Array of FlxPoint nodes. If the end tile could not be found, then a null Array is returned instead.

function destroy():Void

Clean up memory.

function draw():Void

Draws the tilemap buffers to the cameras.

function findPath(Start:FlxPoint, End:FlxPoint, ?Simplify:Bool = true, ?RaySimplify:Bool = false, ?WideDiagonal:Bool = true):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. * *

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. *

WideDiagonal

Whether to require an additional tile to make diagonal movement. Default value is true; *

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.

function follow(?Camera:FlxCamera = null, ?Border:Int = 0, ?UpdateWorld:Bool = true):Void

Call this function to lock the automatic camera to the map's edges. * *

Camera

Specify which game camera you want. If null getScreenXY() will just grab the first global camera. *

Border

Adjusts the camera follow boundary by whatever number of tiles you specify here. Handy for blocking off deadends that are offscreen, etc. Use a negative number to add padding instead of hiding the edges. *

UpdateWorld

Whether to update the collision system's world size, default value is true.

function getBounds(?Bounds:FlxRect = null):FlxRect

Get the world coordinates and size of the entire tilemap as a FlxRect. * *

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.

function getData(?Simple:Bool = false):Array<Int>

Fetches the tilemap data array. * *

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.

function getTile(X:Int, Y:Int):Int

Check the value of a particular tile. * *

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.

function getTileByIndex(Index:Int):Int

Get the value of a tile in the tilemap by index. * *

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.

function getTileCollisions(Index:Int):Int

Gets the collision flags of tile by index. * *

Index

Tile index returned by getTile or getTileByIndex *

returns

The internal collision flag for the requested tile.

function getTileCoords(Index:Int, ?Midpoint:Bool = true):Array<FlxPoint>

Returns a new array full of every coordinate of the requested tile type. * *

Index

The requested tile type. *

Midpoint

Whether to return the coordinates of the tile midpoint, or upper left corner. Default is true, return midpoint. *

returns

An Array with a list of all the coordinates of that tile type.

function getTileInstances(Index:Int):Array<Int>

Returns a new array full of every map index of the requested tile type. * *

Index

The requested tile type. *

returns

An Array with a list of all map indices of that tile type.

function loadMap(MapData:Dynamic, TileGraphic:Dynamic, ?TileWidth:Int = 0, ?TileHeight:Int = 0, ?AutoTile:Int = 0, ?StartingIndex:Int = 0, ?DrawIndex:Int = 1, ?CollideIndex:Int = 1):FlxTilemap

Load the tilemap with string data and a tile graphic. * *

MapData

A string of comma and line-return delineated indices indicating what order the tiles should go in, or an Array of Int. YOU MUST SET widthInTiles and heightInTyles manually BEFORE CALLING loadMap if you pass an Array! *

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 :)

function overlaps(ObjectOrGroup:FlxBasic, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):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! * *

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the two objects overlap.

function overlapsAt(X:Float, Y:Float, ObjectOrGroup:FlxBasic, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):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! * *

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the two objects overlap.

function overlapsPoint(WorldPoint:FlxPoint, ?InScreenSpace:Bool = false, ?Camera:FlxCamera = null):Bool

Checks to see if a point in 2D world space overlaps this FlxObject object. * *

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 getScreenXY() will just grab the first global camera. *

returns

Whether or not the point overlaps this object.

function overlapsWithCallback(Object:FlxObject, ?Callback:FlxObject ->FlxObject ->Bool = null, ?FlipCallbackParams:Bool = false, ?Position:FlxPoint = null):Bool

Checks if the Object overlaps any tiles with any collision flags set, * and calls the specified callback function (if there is one). * Also calls the tile's registered callback if the filter matches. * *

Object

The FlxObject you are checking for overlaps against. *

Callback

An optional function that takes the form "myCallback(Object1:FlxObject,Object2:FlxObject)", where Object1 is a FlxTile object, and Object2 is the object passed in in the first parameter of this method. *

FlipCallbackParams

Used to preserve A-B list ordering from FlxObject.separate() - returns the FlxTile object as the second parameter instead. *

Position

Optional, specify a custom position for the tilemap (useful for overlapsAt()-type funcitonality). *

returns

Whether there were overlaps, or if a callback was specified, whatever the return value of the callback was.

function ray(Start:FlxPoint, End:FlxPoint, ?Result:FlxPoint = null, ?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. * *

Start

The world coordinates of the start of the ray. *

End

The world coordinates of the end of the ray. *

Result

An optional point containing the first wall impact if there was one. Null otherwise. *

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.

function setCustomTileMappings(mappings:Array<Int>, ?randomIndices:Array<Int> = null, ?randomChoices:Array<Array<Int>> = null, ?randomLambda:Void ->Float = null):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. * *

mappings

Array of ints for remapping tiles. Ex: [7,4,12] means "0-->7, 1-->4, 2-->12" *

randomIndices

(optional) Array of ints indicating which tile indices should be randmoized. Ex: [7,4,12] means "replace tile index of 7, 4, or 12 with a randomized value" *

randomChoices

(optional) 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

(optional) 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.

function setDirty(?Dirty:Bool = true):Void

Set the dirty flag on all the tilemap buffers. * Basically forces a reset of the drawn tilemaps, even if it wasn'tile necessary. * *

Dirty

Whether to flag the tilemap buffers as dirty or not.

function setTile(X:Int, Y:Int, Tile:Int, ?UpdateGraphics:Bool = true):Bool

Change the data and graphic of a tile in the tilemap. * *

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.

function setTileByIndex(Index:Int, Tile:Int, ?UpdateGraphics:Bool = true):Bool

Change the data and graphic of a tile in the tilemap. * *

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.

function setTileProperties(Tile:Int, ?AllowCollisions:Int = 4369, ?Callback:FlxObject ->FlxObject ->Void = null, ?CallbackFilter:Class<Dynamic> = null, ?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(). * *

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:FlxTile, 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.

function tileToFlxSprite(X:Int, Y:Int, ?NewTile:Int = 0):FlxSprite

Change a particular tile to FlxSprite. Or just copy the graphic if you dont want any changes to mapdata itself. * * @link http://forums.flixel.org/index.php/topic,5398.0.html *

X

The X coordinate of the tile (in tiles, not pixels). *

Y

The Y coordinate of the tile (in tiles, not pixels). *

NewTile

New tile to the mapdata. Use -1 if you dont want any changes. Default = 0 (empty) *

returns

FlxSprite.

function updateBuffers():Void

Use this method so the tilemap buffers are updated, eg when resizing your game

function updateFrameData():Void

Use this method for creating tileSheet for FlxTilemap. Must be called after loadMap() method. * If you forget to call it then you will not see this FlxTilemap on c++ target