Skip to content

Instantly share code, notes, and snippets.

@MattMcFarland
Created May 2, 2011 09:15
Show Gist options
  • Save MattMcFarland/951341 to your computer and use it in GitHub Desktop.
Save MattMcFarland/951341 to your computer and use it in GitHub Desktop.
/**
* Searches the map for tiles then adds them to the stage
* @param map
* @param l
* @return
*/
private static function scanMapByTileOnLayer(map:Map,l:DataTileLayer):Array
{
var newTiles:Array = new Array();
var tileIndex:int = 0;
for (var tileX:int = 0; tileX < map.width; tileX++) {
for (var tileY:int = 0; tileY < map.height; tileY++) {
var destX:int = (tileX * -map.tileWidth / 2) - (tileY * -map.tileWidth / 2);
var destY:int = (tileY * map.tileHeight / 2) + (tileX * map.tileHeight / 2);
var tile:int = l.tiles[tileIndex];
for each (var t:DataTileSet in map.tileSetData) {
if (tile < t.maxTiles && tile >= t.firstGid) {
var newTile:Image = new Image(t.image, new Rectangle(t.tileRow[tile], t.tileCol[tile], t.tileWidth, t.tileHeight));
newTile.x = destX - t.tileWidth, newTile.y = destY - t.tileHeight;
newTiles.push(newTile);
}
}
tileIndex++;
}
}
return newTiles;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment