# C++ SFML and Box2D: Move world or move player?

I'm currently making a top-down shooter game and it's my first time developing with SFML. I came across and issue and I want to know if there is a better way to solve it.

I need to get the "camera" to move around with the player. I can think of two ways to do this: 1) move the world around the player and keep the player in the same spot to keep the illusion that the player is moving. Or 2) actually make the player move and have the camera follow. The problem with the latter is that (as far as I'm aware) there isn't any way to move the SFML "camera" because there isn't one, it just draws stuff on the window according to where you tell it to, so I have to go with the first option. The reason I'm asking this on here is to see if anyone can recommend a better method because I'm fearful that by moving the world it will mess with the physics and drastically effect the performance of the game.

• @Superdoggy It's actually a 2D game, and I actually did a bit of research and found out that SFML has "Views" which can be used as cameras. I just couldn't find a "Camera" class while exploring the library – MagnusCaligo Jul 2 '15 at 4:24
• In 3D games it's usually better to move the camera. In 2D ones it's really up to you. Moving the world is pretty easy, just tack a scrollX and scrollY variable onto everything. Or move the camera instead. Your choice - there really is no right answer, or at least IMO! :P – Superdoggy Jul 2 '15 at 4:27
• Sorry I had misread your question and was in the middle of deleting / reposting an edited version of my comment when you posted. :P – Superdoggy Jul 2 '15 at 4:28
• sf::View is exactly what other libraries consider a camera. The width and height essentially define the area exposed, while the center determines the position. – Mario Jul 2 '15 at 8:14
• Is this page of the manual what you're looking for? – Alexandre Vaillancourt Jul 2 '15 at 11:05

## 1 Answer

You're right, it can be done in two ways:

-Moving the player -Moving the world

This seems like a 50-50 deal. It doesn't matter how you do it, right?

I don't agree. I would ALWAYS suggest moving the player. Because if you choose to move the world now, and a few months further on in development, when you have enemies, npc's, and other entities on screen, you might change your mind about the camera. You might want to center the camera on an enemy for a second. You might want to center the camera on a door that's opening because of the button you're standing on (Legend of Zelda, anyone?). You also might decide that you don't want to center the camera on the player, but you want it centered between your character and the crosshair (if you don't understand what I mean by that, check out "Soldat", it's a fun little shooter).

Anyway, long story short: Flexibility is added by moving the player.