For our school project we'd like to develop a game using the MVC pattern. We're all moderate new java programmers and absolutely new in game development.

With our current view (containing only menu) using swing we have no issues. But we'd like to make the menu navigation within the game loop. And there's the issue: The game loop prevents the controller to continue. The solution sounds easy, but the implementation lacks some of my/our knowledge, additional thread. I think using a separate thread for view makes handling all stuff threadsafe difficult.

Our game loop is based on nifty, which is using slick2d and this is based on lwjgl (and so on). Reverting to swing does not solve our issue, because once we're in the real game loop, the situation would be the same (so far I understand).

I hope it is understandable without posting huge amount of code. Two questions comes to mind: How should threading be done, when my current try is having a (looping) view instance in its own thread? (Reading a bit here on gamedev seems to call our architecture in question) Is MVC the right choice if we're using slick as framework?


1 Answer 1



I suggest you use just one thread for now. In my opinion, using multiple threads for rendering and game interactions will only complicate your code and introduce synchronization overhead, so the only time I would do that is if I MUST improve performance by using multiple threads for multiple CPUs (in which case you should profile first before optimizing). However, you should still keep your code modular which is where MVC comes in.


The main idea that you should take from MVC is to separate rendering logic and game logic. The Model maintains state information about the game and View simply reads that state from the Model and render it. Controller should be hooked up to handle input and modify the Model as well as initiating the update on the View.

A good example of a single thread MVC-ish game is https://github.com/libgdx/libgdx/tree/master/demos/superjumper/superjumper/src/com/badlogicgames/superjumper

It's based on LibGDX (cross platform Java game library).


You must log in to answer this question.

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