Hello everyone
I'm currently working on a hexagonal tile based game and I got a little problem when it comes to layers.
Since in the game, all Layers are not forced to be drown at the same time I use only one vertexArray to stock the Layers of the map. When I have to draw all of them, I will just call my drawing function for layer-0,-1,-2,...,layer-N.
Given that each layer has a different texture, a specific texture is set for every single one of them.
The problem I got is that even with a color mask for each texture, while drown, tiles of inferior layers with no Tiles above them ( so they're theorically visible ) are not shown.
Here are my drawing functions:
bool MapManager::displayGlobalMap(sf::RenderWindow &window, int Layer)
{
if (m_mapLoaded and Layer < m_Layers)
{
int tileType;
int textureX,textureY;
m_CurrentTileSet = Layer;
Vector2f Center(0,0);
m_vertices.setPrimitiveType(Quads);
m_vertices.resize(m_TileNumber * 4);
for (int j(0); j < m_MapSize.y; ++j)
{
for (int i(0); i < m_MapSize.x; ++i)
{
tileType = m_Map[i][j][Layer]; // le numéro de tuiles dans le set
textureX = tileType % (LayersTilesets[Layer].getSize().x / m_TileSize.x);
textureY = tileType / (LayersTilesets[Layer].getSize().x / m_TileSize.x);
Vertex* quad = &m_vertices[(i + j * m_MapSize.x) * 4]; // on récupere 4 vertex(quads) que l'on va modifié
Center = Vector2f(m_TileSize.x * ( (0.5*(j%2) + i) ), 0.75 * m_TileSize.y * j );
// Position des vertex par rapport au centre
quad[0].position = Center + Vector2f(+m_TileSize.x/2 , -m_TileSize.y/2);
quad[1].position = Center + Vector2f(-m_TileSize.x/2 , -m_TileSize.y/2);
quad[2].position = Center + Vector2f(-m_TileSize.x/2 , +m_TileSize.y/2);
quad[3].position = Center + Vector2f(+m_TileSize.x/2 , +m_TileSize.y/2);
// Texturage de la tuile
quad[0].texCoords = sf::Vector2f(textureX * m_TileSize.x, textureY * m_TileSize.y);
quad[1].texCoords = sf::Vector2f((textureX + 1) * m_TileSize.x, textureY * m_TileSize.y);
quad[2].texCoords = sf::Vector2f((textureX + 1) * m_TileSize.x, (textureY + 1) * m_TileSize.y);
quad[3].texCoords = sf::Vector2f(textureX * m_TileSize.x, (textureY + 1) * m_TileSize.y);
}
}
}
window.draw(*this);
return m_mapLoaded;
}
bool MapManager::displayGlobalMap(sf::RenderWindow &window)
{
for (int i(0); i < m_Layers; ++i)
{
displayGlobalMap(window, i);
}
}
So i guessed it was a bad idea to stock them all in a single VertexArray/ As I understand it, while re-calling the draw function i just redefine the previous vertex, and I just erase from screen the previous layers?
In your opinion, how should I process to display them correctly? Like making multiple vertexArray but then, how do I draw them separately?
Thank you for taking the time to read my lounge post and my bad english