Unsolved Game menu navigation techniques
-
I'm learning Qt and building a game. I'm using C++ so no QML please ;)
I want a game with an initial menu (start, highscores, etc).
And of course the game screen itself.My question is how SHOULD I navigate arround the various screens/menus.
I have a working example which I'll now describe, please advise if I am taking the right approach:
I created a Game class that inherits QMainWindow and I have added QGraphicsView with a QGraphicsScene (seems to be the way for a game).
I added 2 slots renderMenu, renderGame. The constructor of Game calls renderMenu.
These both first clear the scene, then add a button to the scene and use connect(...) to call the other render method, hence when clicked empties the scene and adds the new content.Code: http://pastebin.com/tcSs0tLR
Is it ok to reuse the scene like this?
Is there a better way?
Should I be creating a separate class for both menu and the actual game screen. If so how should I swap menus then. -
@JaffaCakes said in Game menu navigation techniques:
Is it ok to reuse the scene like this?
Probably. However why not create 2 scenes - one static for the menu and one for whatever else you want to display? Then switching between the two is a simple matter to change the scene assigned to the view.
-
Cool, that sounds like an idea.
So when the user clicks on start in the menu scene a signal could be emitted to the parent? My main window could have a slot to start the game.
If the user clicks exit in the game scene another signal would be emitted so the main window swaps to the menu scene again. Should I then delete/remove the game sceen or it's contents? Whose job would that be? Either the game scene deletes its content after the signal is sent or the main window deletes the scene and therfore the content. Which is better? -
@JaffaCakes said in Game menu navigation techniques:
So when the user clicks on start in the menu scene a signal could be emitted to the parent? My main window could have a slot to start the game.
If the user clicks exit in the game scene another signal would be emitted so the main window swaps to the menu scene again.I was thinking along those lines yes.
Should I then delete/remove the game sceen or it's contents?
It would really depend on how you structure your application, but I assume you'd want to delete the game scene whenever you don't need it anymore (e.g. "Quit to main menu" is clicked).
Whose job would that be?
The object that is responsible for the scene management. In general the view will not take ownership of the scene (for obvious reasons) so your class will need at some point to destroy/clear it.
Either the game scene deletes its content after the signal is sent or the main window deletes the scene and therfore the content. Which is better?
Again, it's the responsibility of the controller class. Whether this controller class is a separate entity or is the main window depends on how you structure your application. I'd always opt for a separate class that'd do the initializations, setup and cleanup though.