Tilemap - Rombusevil/flixel-gdx GitHub Wiki
FlxTilemap
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.
arrayToCSV() |
Converts a one-dimensional array of tile data to a comma-separated String. |
bitmapToCSV() |
Converts a TextureRegion object to a comma separated String. |
imageToCSV() |
Converts a resource image file to a comma-separated String. |
pixmapToCSV() |
Converts a Pixmap object to a comma-separated String. |
tiledmapToCSV() |
Converts a TileMap object to a comma-separated String. |
loadMap() |
Load the tilemap with String data and a tile graphic. |
Basically what FlxTilemap
does, is convert a source to a String that is valid. The String need to be passed to loadMap()
along with a tile graphic and the dimension of it. Once this is done the FlxTilemap
object contains an array filled with indices. You can then add the object to the state.
int[] data = {1,1,1, etc};
FlxTilemap level = new FlxTilemap();
level.loadMap(FlxTilemap.arrayToCSV(new IntArray(data), 40), FlxTilemap.ImgAuto, 0, 0, FlxTilemap.AUTO);
add(level);
Examples:
Map editors generate a file that contains the map data. Depending on the file format or the encoding, the file can be loaded by libgdx’s GraphicsTileMaps
API.
Software that are tested and work with flixel:
- Tiled (http://www.mapeditor.org)
You can also build a level via FlxTileblock
. It’s a basic “environment object” class, used to create simple walls and floors. It can be filled with a random selection of tiles to quickly add detail.
loadTiles() |
Fills the block with a randomly arranged selection of graphics from the image provided. |
Examples: