2
\$\begingroup\$

In this libgdx tutorial, the author says he's not happy with the circular dependency between the game and the screens.

How can this diagram:

enter image description here

be improved to remove that dependency?

\$\endgroup\$
2
\$\begingroup\$

You can't. Game class is the one that handles the Screens, and the Screens need to be able to communicate with it to tell it which Screen it should set next.

That dependency isn't really a big of a deal. Just having a reference to the Game in your Screens (via the abstract Screen that all of them extends from).

If you want to change that, you would need to create your own Game and Screen classes, with a different design. (Not worth the effort if you ask me)

\$\endgroup\$
  • \$\begingroup\$ OK, so there's no real problems using this model for developing a proper game? \$\endgroup\$ – bot_bot Dec 13 '13 at 7:27
  • \$\begingroup\$ Nop. Just have the Game reference and use it to go from Screen to Screen. (game.setScreen(new SettingsScreen) for example) Nothing wrong with it. \$\endgroup\$ – Lestat Dec 13 '13 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.