In your opinion, how should I process to display them correctly? Like making multiple vertexArray but then, how do I draw them separately?
It is up to you how it is done (but putting everything of the ground into one draw call every frame would be a bit of processing). If you have multiple sf::VertexArray's, you would just have multiple draw calls...
Like so:
sf::VertexArray va1;
sf::VertexArray va2;
sf::VertexArray va3;
renderWindow.draw(va1);
renderWindow.draw(va2);
renderWindow.draw(va3);
In this case, va1...va3 would be the layers.
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?
Yes. Reconstructing a sf::VertexArray every frame during the drawing isn't the best way to go about doing this, for most occasions. Make the sf::VertexArray a property of the class, and update it that way.
A possible way to do this would be (breaking down what is to be done using rough non-UML UML):
Layer (inherited from sf::Drawable)
(**This is optional, whereas it would essentially be a re-implementation of sf::VertexArray, only more specific to this design by only drawing the things within the view of the parent Map)
parent : Map* (the parent map)
draw() const: void (puts each vertex within the view of the parent into the vertex array and draws it, this should probably be broken into two functions)
Map (inherited from sf::Drawable)
layers : std::array<Layer, 5> (this example specifically talks about 5 layers)
draw() const: void (draws each layer to the render target)
updateView() : void (updates the views of each)
In this example, Map has the single purpose of storing and controlling access to the Layer's (the model and controller). Layers have the single purpose of being what is in such a layer (abstracted to also contain only displaying what is visible). You could also abstract Map to contain all of the non-layered objects (possibly entities?), it depends on your use of what it is.
When I have to draw all of them, I will just call my drawing function for layer-0,-1,-2,...,layer-N.
Try storing all of the sf::VertexArray's into a std::vertex (or std::array if you specifically know how many layers to will be), and then when you want to draw the layer, provide the corresponding sf::VertexArray for the layer being drawn.
Also, classes that are call "*Managers" represent a bad programming design. A class should
generally have a single purpose. I recommend structuring out all of the components of your project on paper, and either come up with a better
more specific name or break what is does into smaller classes. (see my above example for a new possible design)
Another small thing, I would put into the sf::VertexArray's things that are currently visible via the sf::RenderWindow's view, to avoid unnecessary processing.
tileType = m_Map[i][j][Layer]
Nested arrays/vectors are not very efficient. Instead, single dimensional array. An example of that can be found
here(<this is a link, people don't seem to notice the difference in colours, apparently).
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.
This may be due to the fact that you aren't checking to see if there is a tile in the layer prior to adding the quad to the sf::VertexArray for that layer. Though, I do not recommend
at all to keep using the name "MapManager" for the class. Redesigning this class to be more specific will help you notice mistakes and problems much more clearly, because that class
only accesses
this, and
this is
only accessed by that class, in which case logic errors can be easily isolated.
I'm currently working on a hexagonal tile based game and I got a little problem when it comes to layers.
You are drawing hexagons which quads?