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.

Static variables

staticdefaultFramePadding:Int

The default frame padding tilemaps will use when their own framePadding is not set

Available since

5.0.0

.

See also:

  • FlxTypedTilemap.framePadding

Constructor

new()

Inherited Variables

Defined by FlxTypedTilemap

@:value(1.0)alpha:Float = 1.0

Set alpha to a number between 0 and 1 to change the opacity of the sprite.

@:value(FlxSprite.defaultAntialiasing)antialiasing:Bool = FlxSprite.defaultAntialiasing

Controls whether the object is smoothed when rotated, affects performance.

Available since

4.1.0

.

See also:

  • FlxSprite.defaultAntialiasing

@:value(null)blend:BlendMode = null

Blending modes, just like Photoshop or whatever, e.g. "multiply", "screen", etc.

@:value(0xffffff)color:FlxColor = 0xffffff

Tints the whole sprite to a color (0xRRGGBB format) - similar to OpenGL vertex colors. You can use 0xAARRGGBB colors, but the alpha value will simply be ignored. To change the opacity use alpha.

@:value(new ColorTransform())read onlycolorTransform:ColorTransform = new ColorTransform()

@:value(null)framePadding:Null<Int> = null

Eliminates tearing on tilemaps by extruding each tile frame's edge out by the specified number of pixels. Ignored if <= 0. If null, defaultFramePadding is used

Note: Changing this only affects future loadMap calls.

Available since

5.4.0

.

See also:

  • FlxTypedTilemap.defaultFramePadding

frames:FlxFramesCollection

Rendering variables.

@:value(FlxPoint.get())read onlyoffset:FlxPoint = FlxPoint.get()

Use to offset the drawing position of the tilemap, just like FlxSprite.

read onlyscale:FlxPoint

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

read onlyscaledHeight:Float

The scaled height of the entire map.

@:value(0)read onlyscaledTileHeight:Float = 0

The scaled height of a single tile.

@:value(0)read onlyscaledTileWidth:Float = 0

The scaled width of a single tile.

read onlyscaledWidth:Float

The scaled width of the entire map.

shader:FlxShader

GLSL shader for this tilemap. Only works with OpenFL Next or WebGL. Avoid changing it frequently as this is a costly operation.

Available since

4.1.0

.

@:value(0)read onlytileHeight:Int = 0

The unscaled height of a single tile.

@:value(0)read onlytileWidth:Int = 0

The unscaled width of a single tile.

Defined by FlxBaseTilemap

@:value(OFF)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

@:value(0)read onlyheightInTiles:Int = 0

@:value(0)read onlytotalTiles:Int = 0

@:value(0)read onlywidthInTiles:Int = 0

Defined by FlxObject

read onlyacceleration:FlxPoint

How fast the speed of this object is changing (in pixels per second). Useful for smooth movement and gravity.

@:value(FlxDirectionFlags.ANY)allowCollisions:FlxDirectionFlags = FlxDirectionFlags.ANY

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions. Use bitwise operators to check the values stored here. Useful for things like one-way platforms (e.g. allowCollisions = UP;). The accessor "solid" just flips this variable between NONE and ANY.

@:value(0)angle:Float = 0

Set the angle (in degrees) of a sprite to rotate it. WARNING: rotating sprites decreases their rendering performance by a factor of ~10x when using blitting!

@:value(0)angularAcceleration:Float = 0

How fast the spin speed should change (in degrees per second).

@:value(0)angularDrag:Float = 0

Like drag but for spinning.

@:value(0)angularVelocity:Float = 0

This is how fast you want this sprite to spin (in degrees per second).

@:value(IMMOVABLE)collisionXDrag:CollisionDragType = IMMOVABLE

Whether this sprite is dragged along with the horizontal movement of objects it collides with (makes sense for horizontally-moving platforms in platformers for example). Use values IMMOVABLE, ALWAYS, HEAVIER or NEVER

Available since

4.11.0

.

@:value(NEVER)collisionYDrag:CollisionDragType = NEVER

Whether this sprite is dragged along with the vertical movement of objects it collides with (for sticking to vertically-moving platforms in platformers for example). Use values IMMOVABLE, ALWAYS, HEAVIER or NEVER

Available since

4.11.0

.

collisonXDrag:Bool

Deprecated: "Use `collisionXDrag`, instead. Note the corrected spelling: `collis(i)onXDrag"

DEPRECATED Whether this sprite is dragged along with the horizontal movement of objects it collides with (makes sense for horizontally-moving platforms in platformers for example).

Apart from having a weird typo, this has been deprecated for collisionXDrag, which allows more options.

@:value(null)debugBoundingBoxColor:Null<FlxColor> = null

Overriding this will force a specific color to be used for debug rect (ignoring any of the other debug bounding box colors specified).

@:value(FlxColor.BLUE)debugBoundingBoxColorNotSolid:FlxColor = FlxColor.BLUE

Color used for the debug rect if allowCollisions == NONE.

Available since

4.2.0

.

@:value(FlxColor.GREEN)debugBoundingBoxColorPartial:FlxColor = FlxColor.GREEN

Color used for the debug rect if this object collides partially (immovable in the case of FlxObject, or allowCollisions not equal to ANY or NONE in the case of tiles in FlxTilemap).

Available since

4.2.0

.

@:value(FlxColor.RED)debugBoundingBoxColorSolid:FlxColor = FlxColor.RED

Color used for the debug rect if allowCollisions == ANY.

Available since

4.2.0

.

read onlydrag:FlxPoint

This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.

@:value(0)elasticity:Float = 0

The bounciness of this object. Only affects collisions. Default value is 0, or "not bouncy at all."

@:value(1)health:Float = 1

Deprecated: "object.health is being removed in version 6.0.0"

Handy for storing health percentage or armor points or whatever.

@:isVarheight:Float

The height of this object's hitbox. For sprites, use offset to control the hitbox position.

@:value(false)ignoreDrawDebug:Bool = false

Setting this to true will prevent the object's bounding box from appearing when FlxG.debugger.drawDebug is true.

@:value(false)immovable:Bool = false

Whether an object will move/alter position after a collision.

read onlylast:FlxPoint

Important variable for collision processing. By default this value is set automatically during at the start of update().

@:value(1)mass:Float = 1

The virtual mass of the object. Default value is 1. Currently only used with elasticity during collision resolution. Change at your own risk; effects seem crazy unpredictable so far!

@:value(10000)maxAngular:Float = 10000

Use in conjunction with angularAcceleration for fluid spin speed control.

read onlymaxVelocity:FlxPoint

If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).

@:value(defaultMoves)moves:Bool = defaultMoves

Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()). FlxObject and FlxSprite default to true. FlxText, FlxTileblock and FlxTilemap default to false.

@:value(null)path:FlxPath = null

The path this object follows. Not initialized by default. Assign a new FlxPath() object and start() it if you want to this object to follow a path. Set path to null again to stop following the path. See flixel.util.FlxPath for more info and usage examples.

@:value(true)pixelPerfectPosition:Bool = true

Whether or not the position of this object should be rounded before any draw() or collision checking.

pixelPerfectRender:Null<Bool>

Whether or not the coordinates should be rounded during rendering. Does not affect copyPixels(), which can only render on whole pixels. Defaults to the camera's global pixelPerfectRender value, but overrides that value if not equal to null.

read onlyscrollFactor:FlxPoint

Controls how much this object is affected by camera scrolling. 0 = no movement (e.g. a background layer), 1 = same movement speed as the foreground. Default value is (1,1), except for UI elements like FlxButton where it's (0,0).

solid:Bool

Whether the object collides or not. For more control over what directions the object will collide from, use collision constants (like LEFT, FLOOR, etc) to set the value of allowCollisions directly.

@:value(FlxDirectionFlags.NONE)touching:FlxDirectionFlags = FlxDirectionFlags.NONE

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts. Use bitwise operators to check the values stored here, or use isTouching(), justTouched(), etc. You can even use them broadly as boolean values if you're feeling saucy!

read onlyvelocity:FlxPoint

The basic speed of this object (in pixels per second).

@:value(FlxDirectionFlags.NONE)wasTouching:FlxDirectionFlags = FlxDirectionFlags.NONE

Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step. Use bitwise operators to check the values stored here, or use isTouching(), justTouched(), etc. You can even use them broadly as boolean values if you're feeling saucy!

@:isVarwidth:Float

The width of this object's hitbox. For sprites, use offset to control the hitbox position.

@:value(0)x:Float = 0

X position of the upper left corner of this object in world space.

@:value(0)y:Float = 0

Y position of the upper left corner of this object in world space.

Defined by FlxBasic

@:value(idEnumerator++)ID:Int = idEnumerator++

A unique ID starting from 0 and increasing by 1 for each subsequent FlxBasic that is created.

@:value(true)active:Bool = true

Controls whether update() is automatically called by FlxState/FlxGroup.

@:value(true)alive:Bool = true

Useful state for many game objects - "dead" (!alive) vs alive. kill() and revive() both flip this switch (along with exists, but you can override that).

camera:FlxCamera

Gets or sets the first camera of this object.

cameras:Array<FlxCamera>

This determines on which FlxCameras this object will be drawn. If it is null / has not been set, it uses the list of default draw targets, which is controlled via FlxG.camera.setDefaultDrawTarget as well as the DefaultDrawTarget argument of FlxG.camera.add.

read onlycontainer:Null<FlxContainer>

The parent containing this basic, typically if you check this recursively you should reach the state

Available since

5.7.0

.

@:value(true)exists:Bool = true

Controls whether update() and draw() are automatically called by FlxState/FlxGroup.

@:value(true)visible:Bool = true

Controls whether draw() is automatically called by FlxState/FlxGroup.

Inherited Methods

Defined by FlxTypedTilemap

destroy():Void

Clean up memory.

draw():Void

Draws the tilemap buffers to the cameras.

@:value({ updateWorld : true, border : 0 })follow(?camera:FlxCamera, border:Int = 0, updateWorld:Bool = true):Void

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

Parameters:

camera

Specify which game camera you want. If null getScreenPosition() 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.

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.

@:value({ midpoint : true })getTileCoords(index:Int, midpoint:Bool = true):Array<FlxPoint>

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

Parameters:

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.

isOnScreen(?camera:FlxCamera):Bool

Check and see if this object is currently on screen. Differs from FlxObject's implementation in that it takes the actual graphic into account, not just the hitbox or bounding box or whatever.

Parameters:

camera

Specify which game camera you want. If null, it will just grab the first global camera.

Returns:

Whether the object is on screen or not.

@:value({ flipCallbackParams : false })overlapsWithCallback(object:FlxObject, ?callback:(FlxObject, FlxObject) ‑> Bool, flipCallbackParams:Bool = false, ?position:FlxPoint):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.

Parameters:

object

The FlxObject you are checking for overlaps against.

callback

An optional function that takes the form myCallback(a:FlxObject, b:FlxObject), where a is a FlxTile, and b is the given object paaram.

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 (used for overlapsAt).

Returns:

Whether there were overlaps, and the result of the callback, if one was specified.

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.

@:value({ resolution : 1 })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.

resolution

Defaults to 1, meaning check every tile or so. Higher means more checks! 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.

Available since

5.0.0

.

@:value({ dirty : true })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't necessary.

Parameters:

dirty

Whether to flag the tilemap buffers as dirty or not.

@:value({ newTile : 0 })tileToSprite(tileX:Int, tileY:Int, newTile:Int = 0, ?spriteFactory:FlxTileProperties ‑> FlxSprite):FlxSprite

Change a particular tile to FlxSprite. Or just copy the graphic if you dont want any changes to map data itself.

Parameters:

tileX

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

tileY

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

newTile

New tile for the map data. Use -1 if you dont want any changes. Default = 0 (empty)

spriteFactory

Method for converting FlxTile to FlxSprite. If null then will be used defaultTileToSprite() method.

Returns:

FlxSprite.

updateBuffers():Void

Use this method so the tilemap buffers are updated, e.g. when resizing your game

Defined by FlxBaseTilemap

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.

Available since

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.

Available since

5.0.0

.

@:value({ stopOnEnd : true, diagonalPolicy : WIDE })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.

Available since

5.0.0

.

@:value({ stopOnEnd : true, diagonalPolicy : WIDE })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.

@:value({ diagonalPolicy : WIDE, simplify : LINE })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.

@:value({ simplify : LINE })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.

Available since

5.0.0

.

@:value({ simple : false })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.

@:value({ collideIndex : 1, drawIndex : 1, startingIndex : 0, tileHeight : 0, tileWidth : 0 })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 :)

@:value({ collideIndex : 1, drawIndex : 1, startingIndex : 0, tileHeight : 0, tileWidth : 0 })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 :)

@:value({ collideIndex : 1, drawIndex : 1, startingIndex : 0, tileHeight : 0, tileWidth : 0 })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 :)

@:value({ collideIndex : 1, drawIndex : 1, startingIndex : 0, tileHeight : 0, tileWidth : 0, scale : 1, invert : false })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 :)

Available since

4.1.0

.

@:value({ inScreenSpace : false })@:access(flixel.group.FlxTypedGroup)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.

@:value({ inScreenSpace : false })@:access(flixel.group.FlxTypedGroup)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.

@:value({ inScreenSpace : false })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.

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.

@:value({ updateGraphics : true })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.

@:value({ updateGraphics : true })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.

@:value({ range : 1, allowCollisions : ANY })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.

Defined by FlxObject

getMidpoint(?point:FlxPoint):FlxPoint

Retrieve the midpoint of this object in world coordinates.

Parameters:

point

Allows you to pass in an existing FlxPoint object if you're so inclined. Otherwise a new one is created.

Returns:

A FlxPoint object containing the midpoint of this object in world coordinates.

getPosition(?result:FlxPoint):FlxPoint

Returns the world position of this object.

Parameters:

result

Optional arg for the returning point.

Returns:

The world position of this object.

getRotatedBounds(?newRect:FlxRect):FlxRect

Calculates the smallest globally aligned bounding box that encompasses this object's width and height, at its current rotation. Note, if called on a FlxSprite, the origin is used, but scale and offset are ignored. Use getScreenBounds to use these properties.

Parameters:

newRect

The optional output FlxRect to be returned, if null, a new one is created.

Returns:

A globally aligned FlxRect that fully contains the input object's width and height.

Available since

4.11.0

.

getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint

Returns the screen position of this object.

Parameters:

result

Optional arg for the returning point

camera

The desired "screen" coordinate space. If null, FlxG.camera is used.

Returns:

The screen position of this object.

hurt(damage:Float):Void

Deprecated: "object.health is being removed in version 6.0.0"

Reduces the health variable of this object by the amount specified in Damage. Calls kill() if health drops to or below zero.

Parameters:

Damage

How much health to take away (use a negative number to give a health bonus).

inlineinWorldBounds():Bool

Check and see if this object is currently within the world bounds - useful for killing objects that get too far away.

Returns:

Whether the object is within the world bounds or not.

isPixelPerfectRender(?camera:FlxCamera):Bool

Check if object is rendered pixel perfect on a specific camera.

inlineisTouching(direction:FlxDirectionFlags):Bool

Handy function for checking if this object is touching a particular surface. Note: These flags are set from FlxG.collide calls, and get reset in super.update().

Parameters:

direction

Any of the collision flags (e.g. LEFT, FLOOR, etc).

Returns:

Whether the object is touching an object in (any of) the specified direction(s) this frame.

inlinejustTouched(direction:FlxDirectionFlags):Bool

Handy function for checking if this object is just landed on a particular surface. Note: These flags are set from FlxG.collide calls, and get reset in super.update().

Parameters:

direction

Any of the collision flags (e.g. LEFT, FLOOR, etc).

Returns:

Whether the object just landed on (any of) the specified surface(s) this frame.

reset(x:Float, y:Float):Void

Handy function for reviving game objects. Resets their existence flags and position.

Parameters:

x

The new X position of this object.

y

The new Y position of this object.

@:value({ axes : XY })inlinescreenCenter(axes:FlxAxes = XY):FlxObject

Centers this FlxObject on the screen, either by the x axis, y axis, or both.

Parameters:

axes

On what axes to center the object (e.g. X, Y, XY) - default is both.

Returns:

This FlxObject for chaining

@:value({ y : 0.0, x : 0.0 })setPosition(x:Float = 0.0, y:Float = 0.0):Void

Helper function to set the coordinates of this object. Handy since it only requires one line of code.

Parameters:

x

The new x position

y

The new y position

setSize(width:Float, height:Float):Void

Shortcut for setting both width and Height.

Parameters:

width

The new hitbox width.

height

The new hitbox height.

toString():String

Convert object to readable string name. Useful for debugging, save games, etc.

update(elapsed:Float):Void

Override this function to update your class's position and appearance. This is where most of your game rules and behavioral code will go.

Defined by FlxBasic

getCameras():Array<FlxCamera>

The cameras that will draw this. Use this.cameras to set specific cameras for this object, otherwise the container's cameras are used, or the container's container and so on. If there is no container, say, if this is inside FlxGroups rather than a FlxContainer then the default draw cameras are returned.

Available since

5.7.0

.

kill():Void

Handy function for "killing" game objects. Use reset() to revive them. Default behavior is to flag them as nonexistent AND dead. However, if you want the "corpse" to remain in the game, like to animate an effect or whatever, you should override this, setting only alive to false, and leaving exists true.

revive():Void

Handy function for bringing game objects "back to life". Just sets alive and exists back to true. In practice, this function is most often called by FlxObject#reset().