Doubt about creating tgui objects.

  • 1 Replies
Doubt about creating tgui objects.
« on: 16 May 2017, 22:56:15 »
I have multiple game states, each with their buttons and stuff.

So far, I've created a single tgui object, and pass a pointer around, everytime I enter a game state, I create the buttons and add to the gui, and everytime I quit a game state, I do gui->removeAllWidgets(), and clear everything.

But it just ocurred to me (years later than it should), that maybe I should create a gui object for each game state, and create and load the buttons on the constructor of each game state, so switching between game states should be faster, because everything is already created.

Is that ok? Having multiple tgui objects? Also, if I continue my current scheme (lots of code to change if swith), can I expect any problems?



  • *****
  • 1612
    • View Profile
    • Texus's Blog
Re: Doubt about creating tgui objects.
« Reply #1 on: 16 May 2017, 23:02:43 »
Although it would work, it is not advised to have multiple Gui objects. Instead you should rather create a Panel widget for each game state and add all widgets for that state to the panel. That way changing the state just means hiding and showing a panel.

Other than having a longer load time (as you would initialize all states when the program starts), I don't foresee any problems.