示例#1
0
    public void BuildTiles(TiledMap tiledMap, string tilesetName)
    {
        // Index Tiled data
        TiledMap.Layer   layer   = tiledMap.layers[BACKGROUND_LAYER];
        TiledMap.Tileset tileset = tiledMap.tilesets[tilesetName];

        // Reverse grid Y-axis
        int[] grid = new int[layer.grid.Length];
        System.Array.Copy(layer.grid, grid, grid.Length);
        ConvertGridToYUp(grid, layer.width, layer.height);

        // Build tiles
        BuildTiles(grid, layer.width, layer.height, tileset.firstgid, tileset.tileWidth, tileset.tileHeight);
    }
示例#2
0
    /// <summary>
    /// Generates a single mesh collider from Tiled data.
    /// Only relevant faces are computed.
    /// Impprovement notes :
    /// - Meshes could be separated if the max vertice count is reached (65536)
    /// - Could use triangle strips instead of individual triangles
    /// - Have more shapes available (only boxes are supported)
    /// </summary>
    /// <param name='tiledMap'>Tiled map.</param>
    public void BuildMeshCollider(TiledMap tiledMap)
    {
        // Index Tiled data
        TiledMap.Layer   layer   = tiledMap.layers [COLLISION_LAYER];
        TiledMap.Tileset tileset = tiledMap.tilesets [COLLISION_TILESET];
        int[]            grid    = new int[layer.grid.Length];

        // Reverse grid Y-axis
        System.Array.Copy(layer.grid, grid, grid.Length);
        ConvertGridToYUp(grid, layer.width, layer.height);

        // Build collider
        BuildMeshCollider(grid, layer.width, layer.height, tileset.firstgid);
    }