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.

Constructor

new()

Variables

alpha:Float = 1.0

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

antialiasing:Bool = false

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

Available since

4.1.0

.

blend:BlendMode = null

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

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.

read onlycolorTransform:ColorTransform = new ColorTransform()

frames:FlxFramesCollection

Rendering variables.

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!

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

.

useScaleHack:Bool = true

Try to eliminate 1 px gap between tiles in tile render mode by increasing tile scale, so the tile will look one pixel wider than it is.

Methods

destroy():Void

Clean up memory.

draw():Void

Draws the tilemap buffers to the cameras.

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.

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.

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

Returns:

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

ray(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.

Parameters:

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.

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.

tileToSprite(X:Int, Y: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.

@link http://forums.flixel.org/index.php/topic,5398.0.html

Parameters:

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

Inherited Variables

Defined by FlxBaseTilemap

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

read onlyheightInTiles:Int = 0

read onlytotalTiles:Int = 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.

allowCollisions:Int = 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.

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!

angularAcceleration:Float = 0

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

angularDrag:Float = 0

Like drag but for spinning.

angularVelocity:Float = 0

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

collisonXDrag:Bool = true

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

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

debugBoundingBoxColorNotSolid:FlxColor = FlxColor.BLUE

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

Available since

4.2.0

.

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 FlxObject.ANY or FlxObject.NONE in the case of tiles in FlxTilemap).

Available since

4.2.0

.

debugBoundingBoxColorSolid:FlxColor = FlxColor.RED

Color used for the debug rect if allowCollisions == FlxObject.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.

elasticity:Float = 0

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

health:Float = 1

Handy for storing health percentage or armor points or whatever.

height:Float

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

ignoreDrawDebug:Bool = false

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

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

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!

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!).

moves:Bool = true

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.

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.

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.

touching:Int = 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).

wasTouching:Int = 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!

width:Float

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

x:Float = 0

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

y:Float = 0

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

Defined by FlxBasic

ID:Int = -1

IDs seem like they could be pretty useful, huh? They're not actually used for anything yet though.

active:Bool = true

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

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 ot 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 FlxCamera.defaultCameras, which is a reference to FlxG.cameras.list (all cameras) by default.

exists:Bool = true

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

visible:Bool = true

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

Inherited Methods

Defined by FlxBaseTilemap

computePathDistance(StartIndex:Int, EndIndex:Int, DiagonalPolicy:FlxTilemapDiagonalPolicy, 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.

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

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

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

Available since

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.

setCustomTileMappings(mappings:Array<Int>, ?randomIndices:Array<Int>, ?randomChoices:Array<Array<Int>>, ?randomLambda:Void‑>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:Int = FlxObject.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.

getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint

Call this function to figure out the on-screen position of the object.

Parameters:

Point

Takes a FlxPoint object and assigns the post-scrolled X and Y values of this object to it.

Camera

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

Returns:

The Point you passed in, or a new Point if you didn't pass one, containing the screen X and Y position of this object.

hurt(Damage:Float):Void

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

Handy function for checking if this object is touching a particular surface. Be sure to check it before calling super.update(), as that will reset the flags.

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

Handy function for checking if this object is just landed on a particular surface. Be sure to check it before calling super.update(), as that will reset the flags.

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.

screenCenter(?axes:FlxAxes):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 - default is FlxAxes.XY / both.

Returns:

This FlxObject for chaining

setPosition(X:Float = 0, Y:Float = 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

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