Here is an example class that I wrote:
class example {
private:
sf::Texture player_texture;
public:
sf::Sprite player_sprite;
example() {
player_texture.loadFromFile(fight_sprite_location);
player_sprite.setTexture(player_texture);
}
};
So the above class lets you make an object of the class and use that object's sprite instead of having to declare the texture and sprite in the main function.
Basically it's for tidying up my main function a bit.
The problem however is that I might want to instantiate multiple instances of the class (all using the same texture itself, just their sprite attributions like position etc differ).
In that case each instance would have a separate texture object, which is a waste because really all the class instances need the same texture.
Is there a way to share a texture amongst object instances without having to allocate a new texture in each of the objects, and without having to declare a texture where the object has been created (I want as less code in main as possible, because I want my friends to be able to read the code).
Maybe something with the static keyword?
thx for reading