Packageorg.flixel
Classpublic class FlxTilemap
InheritanceFlxTilemap Inheritance FlxObject Inheritance FlxBasic Inheritance Object

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
Controls whether update() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_ACTIVECOUNT : uint
[static]
FlxBasic
 Inheritedalive : Boolean
Useful state for many game objects - "dead" (!alive) vs alive.
FlxBasic
 InheritedallowCollisions : uint
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
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
  cameras : Array
FlxTilemap
  collideIndex : uint
What tile index will you start colliding with (default: 1).
FlxTilemap
 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
 Inheritedelasticity : Number
FlxObject
 Inheritedexists : Boolean
Controls whether update() and draw() are automatically called by FlxState/FlxGroup.
FlxBasic
 Inheritedflickering : Boolean
[read-only] Check to see if the object is still flickering.
FlxObject
 Inheritedhealth : Number
Handy for storing health percentage or armor points or whatever.
FlxObject
 Inheritedheight : Number
FlxObject
  heightInTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
 InheritedID : int
IDs seem like they could be pretty useful, huh?
FlxBasic
  ImgAuto : Class
[static]
FlxTilemap
  ImgAutoAlt : Class
[static]
FlxTilemap
 Inheritedimmovable : Boolean
Whether an object will move/alter position after a collision.
FlxObject
 Inheritedlast : FlxPoint
FlxObject
 Inheritedmass : Number
FlxObject
 InheritedmaxAngular : Number
Use in conjunction with angularAcceleration for fluid spin speed control.
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
 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
FlxObject
  startingIndex : uint
The first index of your tile sheet (default: 0) If you want to change it, do so before calling loadMap().
FlxTilemap
  totalTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
 Inheritedtouching : uint
Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts and collision qualities.
FlxObject
 Inheritedvelocity : FlxPoint
The basic speed of this object.
FlxObject
 Inheritedvisible : Boolean
Controls whether draw() is automatically called by FlxState/FlxGroup.
FlxBasic
 Inherited_VISIBLECOUNT : uint
[static]
FlxBasic
 InheritedwasTouching : uint
FlxObject
 Inheritedwidth : Number
FlxObject
  widthInTiles : uint
Read-only variable, do NOT recommend changing after the map is loaded!
FlxTilemap
 Inheritedx : Number
FlxObject
 Inheritedy : Number
FlxObject
Protected Properties
 PropertyDefined By
  _buffers : Array
FlxTilemap
  _callbacks : Array
FlxTilemap
  _data : Array
FlxTilemap
  _flashPoint : Point
Rendering helper.
FlxTilemap
  _flashRect : Rectangle
FlxTilemap
 Inherited_flicker : Boolean
Internal helper used for retro-style flickering.
FlxObject
 Inherited_flickerTimer : Number
Internal helper used for retro-style flickering.
FlxObject
 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
  _tileHeight : uint
FlxTilemap
  _tileObjects : Array
FlxTilemap
  _tiles : BitmapData
FlxTilemap
  _tileWidth : uint
FlxTilemap
Public Methods
 MethodDefined By
  
The tilemap constructor just initializes some basic variables.
FlxTilemap
  
arrayToCSV(Data:Array, Width:int, Invert:Boolean = false):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
  
destroy():void
[override]
FlxTilemap
  
draw():void
[override] Draws the tilemap.
FlxTilemap
 Inherited
flicker(Duration:Number = 1):void
Tells this object to flicker, retro-style.
FlxObject
  
follow(Camera:FlxCamera = null, Border:int = 0, UpdateWorld:Boolean = true):void
Call this function to lock the automatic camera to the map's edges.
FlxTilemap
  
getData(Simple:Boolean = false):Array
FlxTilemap
 Inherited
FlxObject
 Inherited
getScreenXY(Point:FlxPoint = null, Camera:FlxCamera = 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
  
imageToCSV(ImageFile:Class, Invert:Boolean = false, Scale:uint = 1):String
[static] Converts a resource image file to a comma-separated string.
FlxTilemap
 Inherited
isTouching(Direction:uint):Boolean
FlxObject
 Inherited
justTouched(Direction:uint):Boolean
FlxObject
 Inherited
kill():void
FlxBasic
  
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(Camera:FlxCamera = null):Boolean
[override] Check and see if this object is currently on screen.
FlxObject
  
overlaps(Object:FlxObject):Boolean
[override] Checks for overlaps between the provided object and any tiles above the collision index.
FlxTilemap
  
overlapsPoint(X:Number, Y:Number, Camera:FlxCamera = null, PerPixel:Boolean = false):Boolean
[override] Checks to see if a point in 2D space overlaps a solid tile.
FlxTilemap
  
overlapsWithCallback(Object:FlxObject, Callback:Function = null):Boolean
FlxTilemap
 Inherited
postUpdate():void
[override]
FlxObject
 Inherited
preUpdate():void
[override]
FlxObject
  
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
 Inherited
reset(X:Number, Y:Number):void
Handy function for reviving game objects.
FlxObject
 Inherited
revive():void
FlxBasic
 Inherited
separate(Object1:FlxObject, Object2:FlxObject):Boolean
[static]
FlxObject
 Inherited
separateX(Object1:FlxObject, Object2:FlxObject):Boolean
[static]
FlxObject
 Inherited
separateY(Object1:FlxObject, Object2:FlxObject):Boolean
[static]
FlxObject
  
setDirty(Dirty:Boolean = true):void
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
  
setTileProperties(Tile:uint, AllowCollisions:uint = 0x1111, Callback:Function = null, Range:uint = 1):void
Adjust collision settings and/or bind a callback function to a range of tiles.
FlxTilemap
 Inherited
toString():String
Convert object to readable string name.
FlxBasic
 Inherited
update():void
[override] Called by the main game loop, handles motion/physics and game logic
FlxObject
Protected Methods
 MethodDefined By
  
autoTile(Index:uint):void
An internal function used by the binary auto-tilers.
FlxTilemap
  
Internal function that actually renders the tilemap to the tilemap buffer.
FlxTilemap
 Inherited
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
 InheritedANY : uint
[static]
FlxObject
  AUTO : uint = 1
[static] Platformer-friendly auto-tiling.
FlxTilemap
 InheritedCEILING : uint = 0x0100
[static]
FlxObject
 InheritedDOWN : uint = 0x1000
[static]
FlxObject
 InheritedFLOOR : uint = 0x1000
[static]
FlxObject
 InheritedLEFT : uint = 0x0001
[static]
FlxObject
 InheritedNONE : uint = 0
[static]
FlxObject
  OFF : uint = 0
[static] No auto-tiling.
FlxTilemap
 InheritedOVERLAP_BIAS : Number = 4
[static]
FlxObject
 InheritedRIGHT : uint = 0x0010
[static]
FlxObject
 InheritedUP : uint = 0x0100
[static]
FlxObject
 InheritedWALL : uint
[static]
FlxObject
Protected Constants
 ConstantDefined By
 Inherited_pZero : FlxPoint
[static] A handy "empty point" object
FlxObject
Property Detail
_buffersproperty
protected var _buffers:Array

_callbacksproperty 
protected var _callbacks:Array

_dataproperty 
protected var _data:Array

_flashPointproperty 
protected var _flashPoint:Point

Rendering helper.

_flashRectproperty 
protected var _flashRect:Rectangle

_rectsproperty 
protected var _rects:Array

_tileHeightproperty 
protected var _tileHeight:uint

_tileObjectsproperty 
protected var _tileObjects:Array

_tilesproperty 
protected var _tiles:BitmapData

_tileWidthproperty 
protected var _tileWidth:uint

autoproperty 
public var auto:uint

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

camerasproperty 
public var cameras:Array

collideIndexproperty 
public var collideIndex:uint

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

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

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

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

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, Invert:Boolean = false):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.
 
Invert:Boolean (default = false) — Recommended only for 1-bit arrays - changes 0s to 1s and vice versa.

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) — 1 pixel = Scale number of tiles. Default is 1.

Returns
String — A comma-separated string containing the level data in a FlxTilemap-friendly format.
destroy()method 
override public function destroy():void

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

Draws the tilemap.

drawTilemap()method 
protected function drawTilemap(Buffer:FlxTilemapBuffer, Camera:FlxCamera):void

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

Parameters

Buffer:FlxTilemapBuffer
 
Camera:FlxCamera

follow()method 
public function follow(Camera:FlxCamera = null, Border:int = 0, UpdateWorld:Boolean = true):void

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

Parameters

Camera:FlxCamera (default = null) — Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
 
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.
 
UpdateWorld:Boolean (default = true)

getData()method 
public function getData(Simple:Boolean = false):Array

Parameters

Simple:Boolean (default = false)

Returns
Array
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 
override public function overlaps(Object:FlxObject):Boolean

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

Parameters

Object:FlxObject — The FlxRect you want to check against.

Returns
Boolean
overlapsPoint()method 
override public function overlapsPoint(X:Number, Y:Number, Camera:FlxCamera = null, 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.
 
Camera:FlxCamera (default = null) — Specify which game camera you want. If null getScreenXY() will just grab the first global camera.
 
PerPixel:Boolean (default = false) — Not available in FlxTilemap, ignored.

Returns
Boolean — Whether or not the point overlaps this object.
overlapsWithCallback()method 
public function overlapsWithCallback(Object:FlxObject, Callback:Function = null):Boolean

Parameters

Object:FlxObject
 
Callback:Function (default = null)

Returns
Boolean
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.
setDirty()method 
public function setDirty(Dirty:Boolean = true):void

Parameters

Dirty:Boolean (default = true)

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.
setTileProperties()method 
public function setTileProperties(Tile:uint, AllowCollisions:uint = 0x1111, Callback:Function = null, Range:uint = 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 overlapWithCallback().

Parameters

Tile:uint — The tile or tiles you want to adjust.
 
AllowCollisions:uint (default = 0x1111) — Modify the tile or tiles to only allow collisions from certain directions, use FlxObject constants NONE, ANY, LEFT, RIGHT, etc. Default is "ANY".
 
Callback:Function (default = null) — The function to trigger, e.g. lavaCallback(Object:FlxObject).
 
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.

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.