0
\$\begingroup\$

The constructor of TiledTileLayer.cs takes 4 simply-named arguments. I'm assuming name is the layer's name but I can't figure out what width and height are supposed to represent.

public TiledTileLayer( TiledMap map, string name, int width, int height ) {}

Is it the width of the map, the width of the tile, the number of tiles? Should I hardcode it or get it from another object?

Thanks

\$\endgroup\$
1
  • \$\begingroup\$ Have you tried figuring it out by reading the class yourself? from the looks of it, they likely mean the width of the map, and they seem to load the tiles based on the map width. The width of the tiles is already defined in the class itself. \$\endgroup\$
    – Steven
    Jan 4, 2018 at 11:35

1 Answer 1

1
\$\begingroup\$

So apparently, if anyone else is wondering, according the populateTilePositions() method, width and height represent the number of tile (horizontally and vertically) and not the width and height in pixels.

TiledTile[] populateTilePositions()
{
    for( var y = 0; y < height; y++ )
    {
        for( var x = 0; x < width; x++ )
        {
            if( tiles[x + y * width] != null )
            {
                tiles[x + y * width].x = x;
                tiles[x + y * width].y = y;
            }
        }
    }

    return tiles;
}

The tiles positions are therefore 0,0, 1,0, 2,0, ..., 0,1, 1,1 etc. until the last one which will be x-1,y-1.

This also means that you can simply pass the values from the map object passed as first parameter like so:

var tiledMap = content.Load<TiledMap>("mytilemap");
var backgroundLayer = new TiledTileLayer(tiledMap, "layername", tiledMap.width, tiledMap.height);

I guess my confusion was due to the fact that those could have been the default values and where not. Maybe something to improve in the future.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .