Viewpoint theory - Moving a small screen in a big room

So i’ve been pondering how I would go about implementing a viewport big room small screen kind of concept, and came up with a litte ‘theory’.

So everything in the game will have 2 x/y variables, a “render X/Y” position, and a “real X/Y” position. When receiving input (key strokes), the object the viewport is following will be affected by having the realX/Y position changed. The renderX/Y will stay the same to keep the player in the center of the screen. It is vice versa for the ‘static’ objects, whose real position stays the same, but and input is received, its render position is kept.

In theory (maybe) this means that the screen will look like the player is moving around a world, when really the world is moving according to the input, but in the background, with the realX/Y coordinates, the physics is being run.

So i hope that makes sense.
:confused:

How about nothing “moves” at all, but rather you modify X and Y offset variables that you use when rendering.

Yea I would do that if i knew what all that meant. :3

Every entity in the world has an X and Y that defines where it is by reference of the origin, or usually the top left corner of the map. When you move your character, you just modify his X and Y accordingly and then center the camera on him/her. The camera is composed of and X and Y offset variable that is used to translate the window. Centering is done by doing this:


xOffset = screenWidth/2 - (character.X + character.Width/2);
yOffset = screenHeight/2 - (character.Y + character.Height/2);

And then when rendering your world, you would translate the scene:


graphics.translate(xOffset,yOffset);