K
K
Kirill Batalin2016-04-01 12:01:06
Java
Kirill Batalin, 2016-04-01 12:01:06

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

3 answer(s)
S
Sergey, 2016-04-01
@kir55rus

Decided to make a simple game.

MVC for applications, for games, it is not applicable, since your UI and subject area are too closely related to each other, and MVC aims to “untie” them. The conflict is already in the phrase:
The model must store data, that is, these are simulations of some processes, AI, physics, etc. Well, sprites are essentially a representation of data. And as you can see, a game without graphics is not a game and does not make sense. But you can change the UI of the application, it does not affect the business logic.
In short, for toys, a slightly different pattern is usually used, called ECS (Entity-Component-system) , which allows you to divide responsibilities a little bit differently.
ps but if you return to MVC - then the third option. What up
The model is responsible not so much for storing the state, but for processing it in general. Well, that is, the outside world knows nothing about the internal state, but this does not mean that the outside world cannot ask for a piece of the state for itself and then store it. View can also store state associated with the view and not affect anything else.

V
Vladimir, 2016-04-01
Khatter @mrKhatter

What is your CONTROLLER doing? @[email protected]

E
Elizaveta Borisova, 2016-04-01
@Elizaveta

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 question

Ask a Question

731 491 924 answers to any question