Hello back again, I got a little problem that I wanted to discuss with many clever and experienced users from this forum.
Let's say that I have class like this for an enemy:
class Enemy
{
sf::Texture texture;
sf::Sprite sprite;
void setProperSpriteRect();
};
I have seen in many little productions classes like this, but I have found an very anxious problem with them.
Let's see another short code:
std::vector<Enemy> enemies;
for(unsigned i{0}; i < enemies.size(); ++i)
{
enemies.push_back(Enemy(x,y,z));
}
This code may look okay, but it's not. Every time I create enemy or I delete it, I have to create or delete one texture! Which for example in my game is like 3000x128 size (I'm using setSpriteRect function to get proper frame of animation). It's not okay, when I need only 1 texture for every entity on the map.
There I need your expertise guys! What is the best way to implement a shared texture for every kind of entity? Personally, I was thinking of:
a) making separate class only for texture loading and returning pointer to texture to every class which needs this texture
b) trying to do something with 'static'?
However, I'm not sure which will be the best to improve performance and reduce memory requisition. Thanks for every reply and helpful tip, good luck!