Answer the question
In order to leave comments, you need to log in
MVC: Who should be in charge of sprites?
Decided to make a simple game. The character must have a movement animation. What is the best way to implement this?
1. The model stores a sprite. The view asks the model for a picture and displays it. In this case, the model itself will think what kind of picture should be given to the view so that there is a running animation.
2. The view stores the image of the run. During rendering, the view asks the model for the "phase" of the run and displays the necessary part of the picture on the screen.
3. The view itself calculates, based on the data from the model, which part of the picture to take. In this case, a lot of calculations will take place in the view, but everything related to rendering will be in the view.
UPD. In option 3, you will have to store the past state ("phase") of the run. But the model should be responsible for storing the states.
Answer the question
In order to leave comments, you need to log in
Decided to make a simple game.
Not all patterns are useful in game development. In games, performance is important, and if you hang model, view, controller on one small sprite, what will happen to 200+ sprites? (Did you test already?) If you want MVC, use it for the entire (partial) state of the game.
The standard implementation of sprites can be found in the game engine sources.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question