SFML community forums

Help => Graphics => Topic started by: CowNation on May 02, 2018, 09:48:43 am

Title: Question about selbaward's tilemap
Post by: CowNation on May 02, 2018, 09:48:43 am
Link to source used:
https://github.com/Hapaxia/SelbaWard/wiki/Tile-Map
My tilemap code:
        //TileMap Stuff
        Tiles = ENG::TextureFromFile(&MainWindow, "Data//Images//tileMap.png", "main", false, false, true);
        for (auto& tile : levelData) { tile = rand() % 3; } // pick one of the four available tiles at "random"
        tileMap.setLevel(levelData); // connect level data
        tileMap.setLevelWidth(Engine::windowSize.x); // width of 125 means that the level data gets processed as if it is 125 x 80
        tileMap.setSize({ 1280, 720 }); // size of tile map's rendered image
        tileMap.setGridSize({ 40, 24 }); // size of tile map grid (number of tiles)
        tileMap.setTexture(Tiles);
        tileMap.setNumberOfTextureTilesPerRow(3);
        tileMap.setTextureTileSize({ 64, 64 }); // actual size of tiles within the texture
        tileMap.setPosition(MainWindow.mapPixelToCoords(Vector2i(0, 0)));
        tileMap.update();
        window->draw(tileMap);
        //TileMap Stuff
what it draws:
https://i.imgur.com/LZiFJgB.png
it only randomly selects the first 7 rows
my tilemap:
https://imgur.com/a/lKJk3SX
I'm not understanding what setSize & setGridSize & setLevelWidth do.
Title: Re: Question about selbaward's tilemap
Post by: Hapax on May 07, 2018, 03:14:50 pm
Hi.

My first question would have to be: are you sure that your level has 10,000 cells (125x80) and not around 800 (this would show 125x7)?

My second question would then have to be: are you sure that Engine::windowSize.x is the width of the level in cells (125, is it?) and not the width of the level in co-ordinates or the width of the window?

With those out of the way, let me attempt to clarify what those three things do:

According to your code, you seem to have setup these three things correctly :)