What is the most practical way to implement camera/viewport to a 2D-game?
I've read, that I should store the object world position instead of position relative to the screen?
I have implemented a simple 2D-game where I load objects and levels from XML-files. Currently the level XML-file looks like this:
<map> <tile obj="ground" x="0" y="555" /> <tile obj="ground" x="16" y="555" /> <tile obj="ground" x="32" y="555" /> ... </map>
All objects have a 2d-vector "position" storing their current location on the screen.
What I want it to be:
In the picture:
- Camera is either 800x600 or 640x480
- Blocks and sprites are 16x16 pixels.
- World size may vary
- The coordinates probably should be normalized relative to the world, not to the screen?
- Viewport position relative to player's x, y and moves when the player reaches camera dead zone (similar to this video).
I'm asking pseudo examples / articles, but if you need to know what I'm using for the development: SDL & C/C++.