But I do understand OOP. I just don't understand the syntax to store objects in the list and have that list/screen-class then 'create' that object as an instance, and then how to safely destroy everything.
Surely it can't be that hard..
It may not be hard to do but it'd require a lot of explaining and code examples which many people don't have the time to provide.
After reading the OP, I might be wrong with this, I believe you want to create a state manager like system to handle changing from state to state. The one that eXpl0it3r created and linked in his post is a perfect example. You have a superclass that will contain all the methods and variables required for each state. Such as, draw, update, init etc.
You then can create child classes of the superclass and create override methods of each method you might require. Inside these child classes would be information related to each state, entites, logic etc.
You could then do for example.
MainGame game;
MainMenu menu;
statemanager.addState(game);
statemanager.addState(menu);
stateManager.changeState(GameState::type::MainGame);
I'm no where near the best C++ programmer on this website but I hope my explanation helps you understand what you need to create. If it still doesn't, go look at the example eXpl0it3r posted.
If you wouldn't just ignore essential parts of my post, then you'd have checkout the given link and would've noticed, that I was also referring to classes in general. STL containers are really not that hard to understand with the right book at hand.
I did check those links out. I appreciate your help. Though I have little idea what 'STL container' is.
You could then do for example.
MainGame game;
MainMenu menu;
statemanager.addState(game);
statemanager.addState(menu);
stateManager.changeState(GameState::type::MainGame);
I was thinking something more like:
screen_create(name,size,color,etc)
object_create(name,etc,...)
place_object_in_screen(objectname,screenname,x,y)
etc.
Not really sure why you'd want to do that but its possible, it might be;
GameState screenCreate(sf::String, sf::Vector2f size, sf::color)
{
newState = gamestate;
newState.setTitle(String);
newState.setSize(size);
newState.setcolour(colour);
return newstate;
}
Entity newEntity((sf::String, sf::Vector2f size, sf::color)
{
newEntity = Entity;
newEntity.setTitle(String);
newEntity.setSize(size);
newEntity.setcolour(colour);
}
GameState::addEntity(Entity newEntity)
{
entityList.push_front(newEntity));
}
gamestate tempState = screenCreate("New Window", sf::vector2f(100,100), sf::colour:green);
entity tempEntity = newEntity("New Entity", sf::vector2f(50,50), sf::colour::orange);
tempState.addEntity(tempEntity);
Is that what you'd want too do?
Inside each gameState might be this;
std::list<Entity*> entityList;