Hey guys,
I'm making a tile-based isometric game (Diablo style) and I'm trying to tackle draw order.
At first I accomplished this by giving all entities a Z value depending on how many tiles there were between them and the player on the Y axis. With the game screen height being 1080p and my tile height being 60p, this resulted my dividing the screen into 18 "rows" or layers to be drawn from top to bottom. I then needed to repeat the following code 18 times with each entity:
if (random_entity.get_Z() == 18)
window.draw(random_entity);
This was crude and unmaintainable, so I looked around and found this:
https://github.com/SFML/SFML/wiki/Tutorial:-Drawable-Group. What I did then was instead create 18 of these Group classes from the tutorial, add a "m_drawables.clear();" function to it and I constantly clear and push_back entities into these groups.
I then finally realized that I wouldn't have to use 18 different groups if I could somehow sort the entities according to their Y positions since whatever's higher on the screen should get drawn first anyway. Unfortunately I have no idea how to even begin implementing this.
From what I understand, the Group class uses a reference_wrapper to store the addresses of sf::drawables; and you use the push_back function to add drawables to it. I know that if it were a simple vector of ints I could just do:
std::sort(m_drawables.begin(), m_drawables.end());
... but it's a vector of objects and I have no idea how to sort the Y or Z values of these sf::drawables.
I hate asking others for code, but in this case at least we could add it to the tutorial. I'm a self-taught c++ enthusiast and I'm learning SFML as I make this game, so I really appreciate any help you can give me.