It's all relative. Really, you're always transforming your view relative to your fixed player position.
So, forgetting the screen for now, let's say you have these 3 steps (representing positions as they update on each game loop):
playerWorldPosition = 50, 100; objectWorldPosition = 60, 200;
playerWorldPosition = 55, 110; objectWorldPosition = 60, 160;
playerWorldPosition = 60, 120; objectWorldPosition = 60, 120;
(as x,y in each case)
As you can see, the player is flying up or jumping up and moving slightly to the right, while the object (could be a powerup) is falling straight down. The player catches the powerup. Now how do you draw this onscreen?
First, let's assume you want your player in the centre of the screen at all times. So the view locks to the player -- this is the simplest approach to visualise. The position of your player will then always be screenCentre
(i.e. screenWidth/2, screenHeight/2
). How then do you get the onscreen position of other objects in the world?
objectScreenPosition = (objectWorldPosition - playerWorldPosition) + screenCentre;
You can see that this formula works even for the actual player, since (playerWorldPosition- playerWorldPosition) + screenCentre
is equal to screenCentre
. So you can apply the same formula to each entity in your game, running through a list. You can use this simple approach to build on for other things (like camera lag, cases where you are in the corner of a level, etc.)