Question

I started developing a game using libgdx. It is actually my second try because when i started the first try i did not know enaught of libgdx. In my first try i had an actor subclass with the logic and the texture in it. Then i started reading Gustavo Steigerts tutorial and i saw that he tryed to separate logic and view. I tryed to do the same, but the view is my actor subclass with informations about size and position, so it has to do the collision detection, which is part of the logic. Also if you search on Google you find that with Scene2d you cannot do the MVC. So is there a way to implement a scene2d game using MVC or should i ignore this patern and have model and view in one class which extends actor?

Was it helpful?

Solution

This is a mostly opinion-based question, but it is one that comes up very often when it comes to scene2d and the MVC pattern.

In general it always makes sense to seperate concerns like the Model-View-Controller pattern tries to do. With scene2d this is not that easy, because Actors have already an act() and a draw() method.

In my opinion you should always try to model your game world (entities) like they are. There should be a Player, maybe a Rocket and maybe a Bunny class/actor/entity and they should know everything they need to know and manage themselves. This is the opposite of an Entity-System-Framework where your entities are made of "parts" and those are controlled by external systems.

Most of the time keeping everything together makes it also more flexible, because you already have everything you need in one place. Your gameplay might change and so will your entities. If you find that your entities get too big, you can still split those up in several parts like a PlayerModel, PlayerController and a PlayerRenderer which need references to each other and then trigger those in your act() and render() methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top