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.


1 Answer 1


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\$
    – anonymous
    Commented Dec 7, 2014 at 14:33
  • 1
    \$\begingroup\$ simple and sweet. \$\endgroup\$ Commented Dec 7, 2014 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
    Commented Dec 7, 2014 at 22:47

Not the answer you're looking for? Browse other questions tagged .