Original Post
Hi, I want to make a game loop in a nice way, where I can use polymorphism to call the correct Update, draw and HandleInput.
What I am thinking is to have a base class Scene, which will have the virtual functions Update,Draw and HandleInput. I will then create separate classes for each of my games states/Scenes. I.e. Login , options, pause, main game which will inherit from the base Scene class.
What I would want to do is this:
Scene* currentScene;
...GameLoop
currentScene->Update()
currentScene->Draw()
currentScene->Handlenput()
But wouldn't I also have to initialise the other scenes? Such as:
Login login;
Pause pause;
And then to change the currentscene, I will do something such as: currentScene = &login
This part is fine, the problem lies in where to put the Scene* currentScene variable and all of the other scene variables such that I can switch to any one of the scenes from INSIDE another scene. So say I was in the login scene, and pressing escape inside this scene means I change it to the MainMenu scene, how can I do it so the Login has access to the Mainmenu variable and also the Scene* ?
Sorry if that didn't make much sense.
What I am thinking is to have a base class Scene, which will have the virtual functions Update,Draw and HandleInput. I will then create separate classes for each of my games states/Scenes. I.e. Login , options, pause, main game which will inherit from the base Scene class.
What I would want to do is this:
Scene* currentScene;
...GameLoop
currentScene->Update()
currentScene->Draw()
currentScene->Handlenput()
But wouldn't I also have to initialise the other scenes? Such as:
Login login;
Pause pause;
And then to change the currentscene, I will do something such as: currentScene = &login
This part is fine, the problem lies in where to put the Scene* currentScene variable and all of the other scene variables such that I can switch to any one of the scenes from INSIDE another scene. So say I was in the login scene, and pressing escape inside this scene means I change it to the MainMenu scene, how can I do it so the Login has access to the Mainmenu variable and also the Scene* ?
Sorry if that didn't make much sense.