Hello, I am quite new to C++ and SFML. I have made a few small games from SFML so far and am really enjoying it. Right now I am trying to create an RPG game, then I realised that unlike my other simpler games I've made previously, this game requires a draw order. I was a little bit stumped on how to do this at first, I tried searching on the forums but couldn't quite get a good understanding.
I have been trying to figure out the best & easiest way to draw sprites in a specific order related to their depth. At the moment the class I have made seems to work so far (see code below) , even though I still need to add a few more features. Am I on the right track for this? Sorry if this is in the wrong section of the forums. Thanks in advance.
Here is what I have come up with so far:
void SceneGraph::addToList(Entity entity, int depth)
{
//drawList.emplace(depth, entity);
drawList.insert ( std::pair<int,Entity>(depth,entity) );
}
void SceneGraph::updateList(sf::Time &deltaTime)
{
// Put our current draw list into a new container
tempDrawList.insert(drawList.begin(), drawList.end());
//tempDrawList = drawList;
// Clear our current draw list
drawList.clear();
//
for(std::multimap<int, Entity>::iterator it=tempDrawList.begin(); it!=tempDrawList.end(); it++)
{
// Add our new updated depth to the list
addToList((*it).second, (*it).second.getDepth());
}
// Clear the temp list now we're done with it
tempDrawList.clear();
}
void SceneGraph::draw(sf::RenderWindow& target)
{
for(std::multimap<int, Entity>::iterator it=drawList.begin(); it!=drawList.end(); it++)
{
(*it).second.draw(target);
}
}