public void UpdateCanvas()
    {
        List <tk2dSparseTile> newTiles = new List <tk2dSparseTile>();

        for (int iLayer = 0; iLayer < layers.Length; ++iLayer)
        {
            tk2dScratchpadLayer layer = layers[iLayer];

            for (int y = 0; y < layer.height; ++y)
            {
                for (int x = 0; x < layer.width; ++x)
                {
                    int k = y * layer.width + x;

                    if (layer.tiles[k] != -1)
                    {
                        newTiles.Add(new tk2dSparseTile(x, y, iLayer, layer.tiles[k]));
                    }
                }
            }
        }

        canvas.tiles = newTiles.ToArray();

        canvas.SortTiles(tileSortLeftToRight, tileSortBottomToTop);

        canvas.UpdateBrushHash();
    }
	public void SetNumLayers(int n) {
		tk2dScratchpadLayer[] newLayers = new tk2dScratchpadLayer[n];
		for (int i = 0; i < n; ++i) {
			newLayers[i] = (i < layers.Length) ? layers[i] : new tk2dScratchpadLayer();
		}
		layers = newLayers;
		SetDimensions(width, height);
	}
 public void SetNumLayers(int n)
 {
     tk2dScratchpadLayer[] newLayers = new tk2dScratchpadLayer[n];
     for (int i = 0; i < n; ++i)
     {
         newLayers[i] = (i < layers.Length) ? layers[i] : new tk2dScratchpadLayer();
     }
     layers = newLayers;
     SetDimensions(width, height);
 }