Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Suppose I have a simple game model (designed with MVC pattern): There is a World, there is a WorldRenderer and there is a GameController.

Now, World is a model of the world, i.e. game state. WorldRenderer holds a reference to the world, and its responsibility is just to draw the game state on the screen. GameController receives user input, updates the model and calls to renderer.

And here is a question: When and how do I draw all the stuff related to input?

For example, the game is to drag the box from one place to other, and there are just two places on the screen where the box can be located. At the beginning, the box is located at first legal place. The player drags the box from the first place to random place on the game screen (illegal place).

I still want to draw a box dragged to this place, and also I want to draw a line between last legal position of the box and current position of the box (under the cursor). Then, when the player releases the mouse button I want to actually change the game state (move the box back to its first position if it was above illegal one, or place it at the second legal position if the box was above it).

The game logic is pretty simple - process the input, see what are new coordinates of the box, and decide whether we should move the box to second legal location or to leave it at its current location (if the input is illegal) when the player releases a mouse button.

Now, drawing the dragged box and the line described above is just a visual improvement - to let the player see where he drags the box. It seems wrong to draw it in WorldRenderer, because in this case WorldRenderer should know about user input, and I want him to know only World. In addition it seems wrong to add additional information to World since this information is only used to improve user visual experience.

So what I supposed to do?

share|improve this question
add comment

1 Answer 1

Your question seems to venture into the area of game engine design, so i'm going to take a generic approach here.

Every game has at least one portion of code that is procedural ; the rendering.

This is often handled by something along the lines of your WorldRenderer. The renderer should be completely agnostic of user input, and get called at (preferably independant) intervals so your game logic can continue running at the same speed while you can adjust the renderer's frame rate if necesary.

The worldRenderer should be aware of the objects in your game world (it's your choice whether this is hierarchical or a flat list) so it can call their corresponding render methods.

The logic of updating and drawing the box that is being dragged should then be in the box's own render method.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.