How do I separate model positions from view positions in MVC?

Posted by tieTYT on Game Development See other posts from Game Development or by tieTYT
Published on 2013-09-20T22:10:41Z Indexed on 2013/10/27 10:19 UTC
Read the original article Hit count: 261

Filed under:
|

Using MVC in games (as opposed to web apps) always confuses me when it comes to the view. How am I supposed to keep the model agnostic of how the view is presenting things?

I always end up giving the Model a position that holds x and y but invariably, these values end up being in units of pixels and that feels wrong. I can see the advantage* of avoiding that but how am I supposed to?

This idea was suggested:

Don't think of it in units of pixels, think of them in arbitrary distance units that just happen map to pixels at a 1:1 ratio. Oh, the resolution is half of what it was? We are now taking the x/y coordinates at 50% value for screen display, and your spells casting range is still 300 units long, which now is 150 pixels.

But those numbers conveniently work out. What do I do if the numbers divide in such a way that I get decimal places? Floating points are unsafe. I think allowing decimal places would eventually cause really weird bugs in my game.

*It'd let me write the model once and write different views depending on the device.

© Game Development or respective owner

Related posts about architecture

Related posts about mvc