Now I can mix the entities with the map render texture but only on the back of the map.
Just making: window.draw(*entity).
I need to render it between layers. By the moment if I draw between layers it draws on the back.
Here is where I create the render texture and draw it with the entities. There are 4 layers and entities are drawn in the second.
void Map::draw_layer(int layer_id, sf::RenderWindow &window)
{
if (tmx_info.num_layers >= layer_id)
{
sf::RenderStates states;
states.texture = &map_layers[layer_id].texture;
texture_map.draw(map_layers[layer_id].map_vertex_array, states);
texture_map.display();
sf::Sprite draw_map(texture_map.getTexture());
window.draw(draw_map,);
if (layer_id == 2)
{
for (auto &j : World::current_level->getSceneVector())
{
assert(j != nullptr);
window.draw(*j);
}
}
}
}
Here it's where I display it. I draw everything but first the entities and later the map causing that I cannot insert between layers.
window.clear();
for (unsigned int i = 1; i <= current_level->getNumLayers(); i++)
{
map->draw_layer(i, window);
}
window.display();