This question already has an answer here:

In my rpg-styled (top-down perspective) 2d game, I want my player to be at the center of the screen, while the entire world moves, giving the effect of player movement. I can make that, but my problem is at the edges of the game-world, I want the world to stop moving and the player to move.


marked as duplicate by MichaelHouse Dec 7 '14 at 17:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Don't move the world. Instead move the player and add a third concept called camera which follows the player. Then you can prevent the camera moving too close to the world boundaries. When rendering, subtract camera position from everything.

  • \$\begingroup\$ How to use the third concept called camera ? \$\endgroup\$ – arandomguy Dec 7 '14 at 14:33
  • 1
    \$\begingroup\$ simple and sweet. \$\endgroup\$ – The Light Spark Dec 7 '14 at 15:04
  • 2
    \$\begingroup\$ @Raj - The world stays still, the camera and player both move within the world. The camera follows the player except when the player gets within (screenHeightOrWidth / 2) pixels of the edge of the map. The camera then stays still along that axis until the player comes back past that same point, at which time the camera starts following the player again \$\endgroup\$ – Jon Story Dec 7 '14 at 22:47

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