But how would the player class add its sprite to the GameStates render list? Wouldn't it somehow need to access it to call gameState.AddSprite(mySprite) or something?
1 2 3 4 5 6 7 8 9
|
class Player
{
private:
Sprite sprite;
public:
Player(GameState& gameState){
gameState.AddSprite(&sprite);
}
}
|
Can you come up with a specific example? |
I tried to provide one in my first post, but I don't know how to illustrate it more clearly. Never learned UML or anything like that.
I think of classes/objects kind of like folders.
http://imgur.com/9YS1bW8
So StateManager would "contain" an instance of GameState which in turn contains an instance of Level, which in turn contains instances of Enemies, which would then maybe want to query the level for collision info or something.
I'm probably approaching this in a completely backwards way, it could probably be done a lot better but that's not the point :)
What if an object deep down the "hierarchy" (don't know what else to call it) needs to know the size of the window, to display some text at the center of the window or who knows what? Window does have functions Window::GetWidth() and Window::GetHeight() but to access them inside of a Enemy object, a reference or pointer would need to get passed aaaall the way "down".
By the way, if anyone can tell me the correct terminology for what I'm trying to explain, please go ahead, I'ts hard trying to explain things without the correct words :)