Terry,

// in randomize( ) in TileMap.as we have
// a value sometimes more than 12...
setTile(j, i, (i * numCols) + j);
//       here ^^^^^^^^^^^^^

// But the original has a value never more than 12
setTile(j, i, Math.floor(Math.random()*numTiles));
//       here ^^^^^^^^^^^^^^^^^^^^^^^^^^^

// and this value is passed in as "id" and stored in map[ ][ ] inside function
// setTile(row,col,id ) at Line 32 in TileMap.as
map[row][col] = id;

// and this is used later to identify the tile to use (1 of 12) in the tiles array
// made up of 12 rectangular patches from the original bitmap
// Line 28 in TileMap.as
public function getTile (id:int):ByteArray {
     return tiles[id];    // returns null if id>12
}

// BUT, because id>12 does not exist then thisTile receives null
// in TileMapRenderer line 135
thisTile = tiles.getTile(map.getTile(j, i));
thisTile.position

and that causes the breakdown you see

Glen is right to point you to this code, it's really useful. The main idea is shown below. It uses getPixels to pick out a rectangle of bytes that get stored in the newTileSet array for using later.

// Line 73 in TileSet.as...
public function convertBitmapToTiles (size:int,
                                         data:BitmapData):Array {
     var newTileSet:Array = new Array();
     var numTilesH:int = data.width/size;
     var numTilesV:int = data.height/size;

     for (var i:int = 0; i < numTilesV; i++) {
       for (var j:int = 0; j < numTilesH; j++) {
         newTileSet.push(data.getPixels(new Rectangle(j*size, i*size,
                                                      size, size)));
       }
     }
     return newTileSet;
   }

John

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to