Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool TileMap::load(sf::Texture m_tileset, sf::Vector2u tileSize, vector< vector<Textures::textureTypes> > tiles, unsigned int width, unsigned int height)
- {
- // populate the vertex array, with one quad per tile
- for (unsigned int i = 0; i < width; ++i)
- for (unsigned int j = 0; j < height; ++j)
- {
- // get the current tile number
- int tileNumber = tiles[i][j];
- if (tiles[i][j] == Textures::emptyNpcTile)
- continue;
- // cout << tileNumber;
- // find its position in the tileset texture
- int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
- int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);
- // get a pointer to the current tile's quad
- sf::Vertex* quad = &m_vertices[(i + j * width) * 4];
- // define its 4 corners
- quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
- quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
- quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
- quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
- // define its 4 texture coordinates
- quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
- quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
- quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
- quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement