Hello,
I am trying to create my own game engine based on SFML. I created the scenes, that has the local assets. But I don't understand how to share assets between two scenes, that could replace each other.
Approximate code:
class Level : public AbstractScene
{
public:
Engine& engine;
std::unordered_map<sf::Image> images
Level()
{
images["img1"].loadFromFile("img1.png"); // load image
}
void update()
{
sf::Texture texture(assets.images["img1"]); // use image
...
engine.setScene(new MiniLevel());
}
};
class MiniLevel: public AbstractScene
{
public:
Engine& engine;
std::unordered_map<sf::Image> images;
LevelImages& levelImages; // Level image
MiniLevel(LevelImages& img) : // not real code
levelImages(img)
{
}
void update()
{
sf::Texture texture(levelImages["img1"]); // use Level image
...
engine.setScene(new MiniLevel());
}
};
I know I can use smart pointers to copy images from the Level to MiniLevel, but how to copy it to the Level again? Level class should load images when first created and than only copy it from the MiniLevel. Maybe should I use another class "Level" with the general assets for the scenes?
PS: sorry for my bad English.