This is an update to the tilemap class to be able to change and check the tiles with some functions (which I'm using in
Caverns).
Besides the enhancement of being able to dynamically change the tilemap, you can save memory because you'll be saving the same number of rects (_rects) as tile types in the tileset
against saving as many rects as tiles in the map (imagine a 200x100 tilemap!, 20000 rects against, 30 tops?)
Maybe it was done this way because of an optimization? I don't know, but AFAIK they have the same performance.
Good luck!
-Martín
I did it easily like this: ( //////////// means removed)
@ class definition
////////////private var _rects:FlxArray;
private var _rectsPerType:Array;
private var _drawIndex:uint;
@ constructor
//////////// for(var i:uint = 0; i < numTiles; i++)
//////////// {
//////////// if(_data[i] >= DrawIndex)
//////////// _rects.push(new Rectangle(_tileSize*_data[i],0,_tileSize,_tileSize));
//////////// else
//////////// _rects.push(null);
//////////// }
_drawIndex = DrawIndex;
_rectsPerType = new Array;
for(i = 0; i < _pixels.width / _pixels.height; i++)
{
_rectsPerType.push(new Rectangle(_tileSize*i,0,_tileSize,_tileSize));
}
@ render()
//////////// if(_rects[cri] != null)
//////////// FlxG.buffer.copyPixels(_pixels,_rects[cri],_p,null,null,true);
var tile:uint = _data[c+r*widthInTiles];
if(tile >= _drawIndex)
FlxG.buffer.copyPixels(_pixels,_rectsPerType[tile],_p,null,null,true);
And then an set/get pair of functions that change "_data".