I need to create a public function that runs through an array of sprites and draws them if they are not null
Why do you "need" this, if you don't actually need these "null" sprites?
I tried googling how to do this, but the only thing I found was a lot of people asking for a z axis to be implemented in sfml, and others responding that that would be inefficient and to do this instead. Problem is, everyone's so quick to tell people off but nobody actually wants to actually help or give any idea how to do it
As with most of these claims, when I end up searching for such things myself, I pretty much will always find useful answers.
It's not complicated to implement a z ordering yourself and it allows you to customize the sorting to your own setup. For example a lot of games work more with layers (background, tiles, entities, player).
struct Entity {
Entity(std::string name, int order)
: Name{name}
, Order{order}
{}
std::string Name;
int Order;
};
std::vector<Entity> entities;
entities.emplace_back("Test1", 2);
entities.emplace_back("Test2", 3);
entities.emplace_back("Test3", 1);
std::sort(entities.begin(), entities.end(), [](Entity& a, Entity& b) {
return a.Order < b.Order;
});
Working example:
https://ideone.com/uOCung