public void LoadTiles(JsonTileMap jsonTileMap, Completed completed) { int height = jsonTileMap.MapHeight * jsonTileMap.TileHeight; int width = jsonTileMap.MapWidth * jsonTileMap.TileWidth; for (int x = 0; x < width; x += jsonTileMap.TileWidth) { for (int y = 0; y < height; y += jsonTileMap.TileHeight) { //load just the xy width*height of the canvas into a tile object for caching mostly. var tile = new Tile(x, y, jsonTileMap); //store each tile in a hash of name-x-y loadedTiles[tile.Key] = tile; } } completed(); }
public GameMap(MapManager mapManager, JsonMap jsonMap) { myMapManager = mapManager; Name = jsonMap.Name; MapWidth = jsonMap.MapWidth; MapHeight = jsonMap.MapHeight; TileMap = new Tile[MapWidth][]; CollisionMap = new CollisionType[MapWidth][]; for (int x = 0; x < MapWidth; x++) { TileMap[x] = new Tile[MapHeight]; CollisionMap[x] = new CollisionType[MapHeight]; for (int y = 0; y < MapHeight; y++) { string key = jsonMap.TileMap[x][y]; var tile = myMapManager.myGameManager.TileManager.GetTileByKey(key); TileMap[x][y] = tile; CollisionMap[x][y] = tile.Collision; } } }