Packageorg.flixel
Classpublic class FlxTilemap
InheritanceFlxTilemap Inheritance FlxObject Inheritance FlxRect Inheritance FlxPoint

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 PNG files into strings that can be successfully loaded.



Public Properties
 PropertyDefined by
 Inheritedacceleration : FlxPoint
How fast the speed of this object is changing.
FlxObject
 Inheritedactive : Boolean
If an object is not alive, the game loop will not automatically call update() on it.
FlxObject
 Inheritedangle : Number
Set the angle of a sprite to rotate it.
FlxObject
 InheritedangularAcceleration : Number
How fast the spin speed should change.
FlxObject
 InheritedangularDrag : Number
Like drag but for spinning.
FlxObject
 InheritedangularVelocity : Number
This is how fast you want this sprite to spin.
FlxObject
  auto : uint
Set this flag to use one of the 16-tile binary auto-tile algorithms (OFF, AUTO, or ALT).
FlxTilemap
 Inheritedbottom : Number
The Y coordinate of the bottom of the rectangle.
FlxRect
 InheritedcolHullX : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcolHullY : FlxRect
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 InheritedcollideBottom : Boolean
Flag for direction collision resolution.
FlxObject
  collideIndex : uint
What tile index will you start colliding with (default: 1).
FlxTilemap
 InheritedcollideLeft : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideRight : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcollideTop : Boolean
Flag for direction collision resolution.
FlxObject
 InheritedcolOffsets : Array
An array of FlxPoint objects.
FlxObject
 InheritedcolVector : FlxPoint
These store a couple of useful numbers for speeding up collision resolution.
FlxObject
 Inheriteddead : Boolean
Handy for tracking gameplay or animations.
FlxObject
 Inheriteddrag : FlxPoint
This isn't drag exactly, more like deceleration that is only applied when acceleration is not affecting the sprite.
FlxObject
  drawIndex : uint
What tile index will you start drawing with (default: 1) NOTE: should always be >= startingIndex.
FlxTilemap
 Inheritedexists : Boolean
Kind of a global on/off switch for any objects descended from FlxObject.
FlxObject
 Inheritedfixed : Boolean
Set fixed to true if you want the object to stay in place during collisions.
FlxObject
 Inherited_group : Boolean
Dedicated internal flag for whether or not this class is a FlxGroup.
FlxObject
 Inheritedhealth : Number
Handy for storing health percentage or armor points or whatever.
FlxObject
 Inheritedheight : Number
FlxRect
  heightInTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
  ImgAuto : Class
[static]
FlxTilemap
  ImgAutoAlt : Class
[static]
FlxTilemap
 Inheritedleft : Number
The X coordinate of the left side of the rectangle.
FlxRect
 InheritedmaxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control.
FlxObject
 InheritedmaxThrust : Number
Used to cap thrust, helpful and easy!
FlxObject
 InheritedmaxVelocity : FlxPoint
If you are using acceleration, you can use maxVelocity with it to cap the speed automatically (very useful!).
FlxObject
 Inheritedmoves : Boolean
Set this to false if you want to skip the automatic motion/movement stuff (see updateMotion()).
FlxObject
 InheritedonFloor : Boolean
Flag that indicates whether or not you just hit the floor.
FlxObject
 Inheritedorigin : FlxPoint
WARNING: The origin of the sprite will default to its center.
FlxObject
  refresh : Boolean
Set this flag to true to force the tilemap buffer to refresh on the next render frame.
FlxTilemap
 Inheritedright : Number
The X coordinate of the right side of the rectangle.
FlxRect
 InheritedscrollFactor : FlxPoint
A point that can store numbers from 0 to 1 (for X and Y independently) that governs how much this object is affected by the camera subsystem.
FlxObject
 Inheritedsolid : Boolean
Set solid to true if you want to collide this object.
FlxObject
  startingIndex : uint
The first index of your tile sheet (default: 0) If you want to change it, do so before calling loadMap().
FlxTilemap
 Inheritedthrust : Number
If you want to do Asteroids style stuff, check out thrust, instead of directly accessing the object's velocity or acceleration.
FlxObject
 Inheritedtop : Number
The Y coordinate of the top of the rectangle.
FlxRect
  totalTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
 Inheritedvelocity : FlxPoint
The basic speed of this object.
FlxObject
 Inheritedvisible : Boolean
If an object is not visible, the game loop will not automatically call render() on it.
FlxObject
 Inheritedwidth : Number
FlxRect
  widthInTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
 Inheritedx : Number
FlxPoint
 Inheritedy : Number
FlxPoint
Protected Properties
 PropertyDefined by
  _bbKey : String
FlxTilemap
  _bbPixels : BitmapData
FlxTilemap
  _block : FlxObject
FlxTilemap
  _boundsVisible : Boolean
FlxTilemap
  _buffer : BitmapData
FlxTilemap
  _bufferLoc : FlxPoint
FlxTilemap
  _callbacks : Array
FlxTilemap
  _data : Array
FlxTilemap
 Inherited_fixed : Boolean
Internal tracker for whether an object will move/alter position after a collision (see fixed).
FlxObject
 Inherited_flashPoint : Point
This is a pre-allocated Flash Point object, which is useful for certain Flash graphics API calls
FlxObject
  _flashRect : Rectangle
Rendering helper.
FlxTilemap
  _flashRect2 : Rectangle
FlxTilemap
 Inherited_flicker : Boolean
Internal helper used for retro-style flickering.
FlxObject
 Inherited_flickerTimer : Number
Internal helper used for retro-style flickering.
FlxObject
  _pixels : BitmapData
FlxTilemap
 Inherited_point : FlxPoint
This is just a pre-allocated x-y point container to be used however you like
FlxObject
 Inherited_rect : FlxRect
This is just a pre-allocated rectangle container to be used however you like
FlxObject
  _rects : Array
FlxTilemap
  _screenCols : uint
FlxTilemap
  _screenRows : uint
FlxTilemap
 Inherited_solid : Boolean
Internal tracker for whether or not the object collides (see solid).
FlxObject
  _tileHeight : uint
FlxTilemap
  _tileWidth : uint
FlxTilemap
Public Methods
 MethodDefined by
  
The tilemap constructor just initializes some basic variables.
FlxTilemap
  
arrayToCSV(Data:Array, Width:int):String
[static] Converts a one-dimensional array of tile data to a comma-separated string.
FlxTilemap
  
bitmapToCSV(bitmapData:BitmapData, Invert:Boolean = false, Scale:uint = 1):String
[static] Converts a BitmapData object to a comma-separated string.
FlxTilemap
 Inherited
collide(Object:FlxObject = null):Boolean
If you don't want to call FlxU.collide() you can use this instead.
FlxObject
 Inherited
destroy():void
Called by FlxGroup, commonly when game states are changed.
FlxObject
 Inherited
flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style.
FlxObject
 Inherited
flickering():Boolean
Check to see if the object is still flickering.
FlxObject
  
follow(Border:int = 0):void
Call this function to lock the automatic camera to the map's edges.
FlxTilemap
 Inherited
Returns the appropriate color for the bounding box depending on object state.
FlxObject
 Inherited
getScreenXY(Point:FlxPoint = null):FlxPoint
Call this function to figure out the on-screen position of the object.
FlxObject
  
getTile(X:uint, Y:uint):uint
Check the value of a particular tile.
FlxTilemap
  
getTileByIndex(Index:uint):uint
Get the value of a tile in the tilemap by index.
FlxTilemap
 Inherited
hitBottom(Contact:FlxObject, Velocity:Number):void
Called when this object's bottom edge collides with the top of another FlxObject.
FlxObject
 Inherited
hitLeft(Contact:FlxObject, Velocity:Number):void
Called when this object's left side collides with another FlxObject's right.
FlxObject
 Inherited
hitRight(Contact:FlxObject, Velocity:Number):void
Called when this object's right side collides with another FlxObject's left.
FlxObject
 Inherited
hitSide(Contact:FlxObject, Velocity:Number):void
Since most games have identical behavior for running into walls, you can just override this function instead of overriding both hitLeft and hitRight.
FlxObject
 Inherited
hitTop(Contact:FlxObject, Velocity:Number):void
Called when this object's top collides with the bottom of another FlxObject.
FlxObject
 Inherited
hurt(Damage:Number):void
Call this function to "damage" (or give health bonus) to this sprite.
FlxObject
  
imageToCSV(ImageFile:Class, Invert:Boolean = false, Scale:uint = 1):String
[static] Converts a resource image file to a comma-separated string.
FlxTilemap
 Inherited
kill():void
Call this function to "kill" a sprite so that it no longer 'exists'.
FlxObject
  
loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0):FlxTilemap
Load the tilemap with string data and a tile graphic.
FlxTilemap
 Inherited
onScreen():Boolean
Check and see if this object is currently on screen.
FlxObject
  
overlaps(Core:FlxObject):Boolean
Checks for overlaps between the provided object and any tiles above the collision index.
FlxTilemap
  
overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean
Checks to see if a point in 2D space overlaps a solid tile.
FlxTilemap
  
preCollide(Object:FlxObject):void
FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide.
FlxTilemap
  
ray(StartX:Number, StartY:Number, EndX:Number, EndY:Number, Result:FlxPoint, Resolution:Number = 1):Boolean
Shoots a ray from the start point to the end point.
FlxTilemap
  
refreshHulls():void
Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.
FlxTilemap
  
render():void
Draws the tilemap.
FlxTilemap
 Inherited
reset(X:Number, Y:Number):void
Handy function for reviving game objects.
FlxObject
  
setCallback(Tile:uint, Callback:Function, Range:uint = 1):void
Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles.
FlxTilemap
  
setTile(X:uint, Y:uint, Tile:uint, UpdateGraphics:Boolean = true):Boolean
Change the data and graphic of a tile in the tilemap.
FlxTilemap
  
setTileByIndex(Index:uint, Tile:uint, UpdateGraphics:Boolean = true):Boolean
Change the data and graphic of a tile in the tilemap.
FlxTilemap
 Inherited
toString():String
Convert object to readable string name.
FlxPoint
  
update():void
Checks to see if the tilemap needs to be refreshed or not.
FlxTilemap
Protected Methods
 MethodDefined by
  
autoTile(Index:uint):void
An internal function used by the binary auto-tilers.
FlxTilemap
  
Generates a bounding box version of the tiles, flixel should call this automatically when necessary.
FlxTilemap
  
Internal function that actually renders the tilemap to the tilemap buffer.
FlxTilemap
 Inherited
Just updates the retro-style flickering.
FlxObject
 Inherited
updateMotion():void
Internal function for updating the position and speed of this object.
FlxObject
  
updateTile(Index:uint):void
Internal function used in setTileByIndex() and the constructor to update the map.
FlxTilemap
Public Constants
 ConstantDefined by
  ALT : uint = 2
[static] Top-down auto-tiling.
FlxTilemap
  AUTO : uint = 1
[static] Platformer-friendly auto-tiling.
FlxTilemap
  OFF : uint = 0
[static] No auto-tiling.
FlxTilemap
Protected Constants
 ConstantDefined by
 Inherited_pZero : FlxPoint
[static] A handy "empty point" object
FlxObject
Property detail
autoproperty
public var auto:uint

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

_bbKeyproperty 
protected var _bbKey:String
_bbPixelsproperty 
protected var _bbPixels:BitmapData
_blockproperty 
protected var _block:FlxObject
_boundsVisibleproperty 
protected var _boundsVisible:Boolean
_bufferproperty 
protected var _buffer:BitmapData
_bufferLocproperty 
protected var _bufferLoc:FlxPoint
_callbacksproperty 
protected var _callbacks:Array
collideIndexproperty 
public var collideIndex:uint

What tile index will you start colliding with (default: 1).

_dataproperty 
protected var _data:Array
drawIndexproperty 
public var drawIndex:uint

What tile index will you start drawing with (default: 1) NOTE: should always be >= startingIndex. If you want to change it, do so before calling loadMap().

_flashRectproperty 
protected var _flashRect:Rectangle

Rendering helper.

_flashRect2property 
protected var _flashRect2:Rectangle
heightInTilesproperty 
public var heightInTiles:uint

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

ImgAutoproperty 
public static var ImgAuto:Class
ImgAutoAltproperty 
public static var ImgAutoAlt:Class
_pixelsproperty 
protected var _pixels:BitmapData
_rectsproperty 
protected var _rects:Array
refreshproperty 
public var refresh:Boolean

Set this flag to true to force the tilemap buffer to refresh on the next render frame.

_screenColsproperty 
protected var _screenCols:uint
_screenRowsproperty 
protected var _screenRows:uint
startingIndexproperty 
public var startingIndex:uint

The first index of your tile sheet (default: 0) If you want to change it, do so before calling loadMap().

_tileHeightproperty 
protected var _tileHeight:uint
_tileWidthproperty 
protected var _tileWidth:uint
totalTilesproperty 
public var totalTiles:uint

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

widthInTilesproperty 
public var widthInTiles:uint

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

Constructor detail
FlxTilemap()constructor
public function FlxTilemap()

The tilemap constructor just initializes some basic variables.

Method detail
arrayToCSV()method
public static function arrayToCSV(Data:Array, Width:int):String

Converts a one-dimensional array of tile data to a comma-separated string.

Parameters
Data:Array — An array full of integer tile references.
 
Width:int — The number of tiles in each row.

Returns
String — A comma-separated string containing the level data in a FlxTilemap-friendly format.
autoTile()method 
protected function autoTile(Index:uint):void

An internal function used by the binary auto-tilers.

Parameters
Index:uint — The index of the tile you want to analyze.
bitmapToCSV()method 
public static function bitmapToCSV(bitmapData:BitmapData, Invert:Boolean = false, Scale:uint = 1):String

Converts a BitmapData object to a comma-separated string. Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK.

Parameters
bitmapData:BitmapData — An embedded graphic, preferably black and white.
 
Invert:Boolean (default = false) — Load white pixels as solid instead.
 
Scale:uint (default = 1)

Returns
String — A comma-separated string containing the level data in a FlxTilemap-friendly format.
follow()method 
public function follow(Border:int = 0):void

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

Parameters
Border:int (default = 0) — 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.
generateBoundingTiles()method 
protected function generateBoundingTiles():void

Generates a bounding box version of the tiles, flixel should call this automatically when necessary.

getTile()method 
public function getTile(X:uint, Y:uint):uint

Check the value of a particular tile.

Parameters
X:uint — The X coordinate of the tile (in tiles, not pixels).
 
Y:uint — The Y coordinate of the tile (in tiles, not pixels).

Returns
uint — A uint containing the value of the tile at this spot in the array.
getTileByIndex()method 
public function getTileByIndex(Index:uint):uint

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

Parameters
Index:uint — The slot in the data array (Y widthInTiles + X) where this tile is stored.

Returns
uint — A uint containing the value of the tile at this spot in the array.
imageToCSV()method 
public static function imageToCSV(ImageFile:Class, Invert:Boolean = false, Scale:uint = 1):String

Converts a resource image file to a comma-separated string. Black pixels are flagged as 'solid' by default, non-black pixels are set as non-colliding. Black pixels must be PURE BLACK.

Parameters
ImageFile:Class — An embedded graphic, preferably black and white.
 
Invert:Boolean (default = false) — Load white pixels as solid instead.
 
Scale:uint (default = 1)

Returns
String — A comma-separated string containing the level data in a FlxTilemap-friendly format.
loadMap()method 
public function loadMap(MapData:String, TileGraphic:Class, TileWidth:uint = 0, TileHeight:uint = 0):FlxTilemap

Load the tilemap with string data and a tile graphic.

Parameters
MapData:String — A string of comma and line-return delineated indices indicating what order the tiles should go in.
 
TileGraphic:Class — All the tiles you want to use, arranged in a strip corresponding to the numbers in MapData.
 
TileWidth:uint (default = 0) — The width of your tiles (e.g. 8) - defaults to height of the tile graphic if unspecified.
 
TileHeight:uint (default = 0) — The height of your tiles (e.g. 8) - defaults to width if unspecified.

Returns
FlxTilemap — A pointer this instance of FlxTilemap, for chaining as usual :)
overlaps()method 
public override function overlaps(Core:FlxObject):Boolean

Checks for overlaps between the provided object and any tiles above the collision index.

Parameters
Core:FlxObject — The FlxCore you want to check against.

Returns
Boolean
overlapsPoint()method 
public override function overlapsPoint(X:Number, Y:Number, PerPixel:Boolean = false):Boolean

Checks to see if a point in 2D space overlaps a solid tile.

Parameters
X:Number — The X coordinate of the point.
 
Y:Number — The Y coordinate of the point.
 
PerPixel:Boolean (default = false) — Not available in FlxTilemap, ignored.

Returns
Boolean — Whether or not the point overlaps this object.
preCollide()method 
public override function preCollide(Object:FlxObject):void

FlxU.collide() (and thus FlxObject.collide()) call this function each time two objects are compared to see if they collide. It doesn't necessarily mean these objects WILL collide, however.

Parameters
Object:FlxObject — The FlxObject you're about to run into.
ray()method 
public function ray(StartX:Number, StartY:Number, EndX:Number, EndY:Number, Result:FlxPoint, Resolution:Number = 1):Boolean

Shoots a ray from the start point to the end point. If/when it passes through a tile, it stores and returns that point.

Parameters
StartX:Number — The X component of the ray's start.
 
StartY:Number — The Y component of the ray's start.
 
EndX:Number — The X component of the ray's end.
 
EndY:Number — The Y component of the ray's end.
 
Result:FlxPoint — A Point object containing the first wall impact.
 
Resolution:Number (default = 1) — Defaults to 1, meaning check every tile or so. Higher means more checks!

Returns
Boolean — Whether or not there was a collision between the ray and a colliding tile.
refreshHulls()method 
public override function refreshHulls():void

Called by FlxObject.updateMotion() and some constructors to rebuild the basic collision data for this object.

render()method 
public override function render():void

Draws the tilemap.

renderTilemap()method 
protected function renderTilemap():void

Internal function that actually renders the tilemap to the tilemap buffer. Called by render().

setCallback()method 
public function setCallback(Tile:uint, Callback:Function, Range:uint = 1):void

Bind a function Callback(Core:FlxCore,X:uint,Y:uint,Tile:uint) to a range of tiles.

Parameters
Tile:uint — The tile to trigger the callback.
 
Callback:Function — The function to trigger. Parameters should be (Core:FlxCore,X:uint,Y:uint,Tile:uint).
 
Range:uint (default = 1) — If you want this callback to work for a bunch of different tiles, input the range here. Default value is 1.
setTile()method 
public function setTile(X:uint, Y:uint, Tile:uint, UpdateGraphics:Boolean = true):Boolean

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

Parameters
X:uint — The X coordinate of the tile (in tiles, not pixels).
 
Y:uint — The Y coordinate of the tile (in tiles, not pixels).
 
Tile:uint — The new integer data you wish to inject.
 
UpdateGraphics:Boolean (default = true) — Whether the graphical representation of this tile should change.

Returns
Boolean — Whether or not the tile was actually changed.
setTileByIndex()method 
public function setTileByIndex(Index:uint, Tile:uint, UpdateGraphics:Boolean = true):Boolean

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

Parameters
Index:uint — The slot in the data array (Y widthInTiles + X) where this tile is stored.
 
Tile:uint — The new integer data you wish to inject.
 
UpdateGraphics:Boolean (default = true) — Whether the graphical representation of this tile should change.

Returns
Boolean — Whether or not the tile was actually changed.
update()method 
public override function update():void

Checks to see if the tilemap needs to be refreshed or not.

updateTile()method 
protected function updateTile(Index:uint):void

Internal function used in setTileByIndex() and the constructor to update the map.

Parameters
Index:uint — The index of the tile you want to update.
Constant detail
ALTconstant
public static const ALT:uint = 2

Top-down auto-tiling.

AUTOconstant 
public static const AUTO:uint = 1

Platformer-friendly auto-tiling.

OFFconstant 
public static const OFF:uint = 0

No auto-tiling.