1
\$\begingroup\$

For example I currently have a Player object that contains it's textures/animations and how to render these (I'd consider this as the view). Player also has an update() method which controls where the player is going to move, if it's going to lose health etc. (controller). Finally Player also has all it's attributes like runspeed, health, max health, inventory items etc.

The Player class is starting to look very cluttered and unorganized and serializing the complete Player class isn't really possible, so I made a separate PlayerState class which basically contains all it's attributes that could be changed while playing (This could actually be turned into the PlayerModel). I was wondering if it would be a good idea to split the Player up using a MVC pattern. I would have a Player, PlayerController and PlayerRenderer. Serializing the Player would be easy and it would be easier to keep the rendering separate from the updating and make sure rendering only happens when everything for the next frame has been updated.

This seemed like a good idea, however then I would also want to do this for GameMap. A GameMapRenderer that renders the map and it's textures to the screen. A GameMap model that contains what animals and hostiles are in the map and other various attributes the map might have. And of course a controller that controls everything that happens in that map.

I could go even further and say a Pig may need a model since it has attributes that can change, a renderer to render it's texture and a controller to control movement etc. but this seems a bit excessive. However, I don't like only implementing the MVC pattern to the player and then ignoring it for other classes like Pig. But the way I'm working currently is very badly structured imo and it's frustrating to work with.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

tl'dr

Design Pattern can show you a solution, how this pattern helped many others. If it is suitable for your problem is only known by you. Design Patterns are rather independent of applied technologies (LIBGDX).

Details:

MVC is a Design Patter that evolved from the UI-Design-Problems in the late 70s. What you are trying to explain looks to me like you're trying to do the MVP (Model-View-Presenter), which is similar but might be worth a look.

Summary

your Question is too broad and any answer would be strongly opinion based -> maybe you close it / refine it?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Note that if you feel a question is too broad / opinion-based, you can cast a close vote to that effect. \$\endgroup\$
    – DMGregory
    Jan 8, 2020 at 12:22
  • \$\begingroup\$ i totally agree with you - but i found it note-worthy to point out how design patterns can help you... \$\endgroup\$ Jan 9, 2020 at 5:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .