Accessing Tilemap Tiles Using Coordinate Point Values

Hello -

I’ve been playing around with the tile classes in OpenFL (Tile, Tileset, Tilemap). I’m not a huge fan of how the Tilemap class accesses specific tiles, as I prefer using a method akin to a 2D array (Accessing based on “coordinate points”). I was wondering, is there a way to configure the Tilemap class in order to get that behavior? And if not, would I still be able to use the Tileset class with a custom map structure?

Thanks for any advice.

Just keep track yourself of the tiles. Make your array of arrays (or a single array and do the math for the “line break”) and when you create a tile you position it in it’s iwidth and jwidth.

You could maybe extend Tile into a “GridTile” that does that.

So are you suggesting I don’t use the Tilemap class at all, and instead make a 2D array to store/access my tiles? Or are you suggesting having two separate constructs: a 2D array to store the data and a TIlemap object to draw the map (based on the array data)?

The latter.

Without a Tilemap you won’t be able to render.
Use a 2d array to store the tiles and add the tiles to Tilemap to be able to render them.

If this makes any sense: Think of Tilemap as your Stage, TileContainer as your Sprite and Tiles as your Bitmap
From there, start building your own logic on how to access them.

Edit: Adding some pseudocode for you to be able to materialize the idea:

//your renderer
var map:Tilemap = new Tilemap(...);

//your data structure
var tileGrid:Array<Array<Tile>> = new Array<Array<Tile>>();

//lets populate it
for (i in 0...columns){
   tileGrid[i] = new Array<Tile>();
   for (j in 0...rows){
      //make a new tile
      var aux:Tile = new Tile(1, i*tileWidth, j*tileHeight);

      //save it to your data structure
      tileGrid[i][j] = aux;

      //add it to the renderer

and let’s say you want to make the tile at 2,3 invisible you do:
tileGrid[2][3],visible = false

Thank you! That helped a bunch.

Perhaps we could consider having either types of tilemaps (isometric, orthogonal, etc) for auto-sorting, or add a sort function if we don’t have one already

Inside a TileContainer, the array called __tiles can be sorted (the method “sort” of array) and this changes the z-order of the rendering. A sort function for tilecontainer is really simple (I have made a “SortableContainer” extending tilecontainer). I will send a PR later today :+1:

Edit: Later today…

Merged and renamed to tilemap.sortTiles :slight_smile: