views:

166

answers:

4

I'm not sure if this question fits properly, but I'm wondering in tile-based games, does the tiles 'shift' when the player is moving (and the player stays in the same place) or does the player move instead (and instead the tiles stay in the same place)?

+8  A: 

Visually or in the model?

Visually, there’s usually some code that keeps the player fixed in the middle of the screen while the tiles scroll under him, with the tiles stopping and the player moving to the edge of the screen when the end of the map is reached. Typically this implies some sort of camera that knows how to follow the player, and perhaps changes its behavior depending on which direction the player is facing, and can also be locked for special effects and cutscenes.

In the model, it makes no sense to update the positions of all the tiles and every single object relative to the player, when you could instead just move the player.

jleedev
I'm going to mark this as the answer though all the answers were great (+1 to all). I guess it's the model then. The part I wasn't sure about was when the player moved after the tiles hit the end.
DMan
+2  A: 

Well, the specifics of how you want to draw it are up to you. Some tile-based games show the player fixed in the center of the screen -- in that case, your function to draw the character sprite always centers the character, while the function to draw the background would take an offset.

Others might give the player a pixel offset as well, either to show movement or to give "edges" to a map, not allowing the player to see what lies beyond.

How you implement it in your game is really up to you -- there's no "right" way to draw your sprites.

Ryan Prior
+1  A: 

The tiles do. Unless there's no more to scroll in a certain direction, then the character moves. It's better to have as much as possible that's static cached together rather than move all the tiles individually.

Jimmy Ruska
A: 

The player moves, and the camera moves. The tiles are drawn shifted by the camera's position so that the world appears to scroll while the player stays roughly centered on screen. The camera follows the player, but usually a little loosely. (For example, you'll notice that you can walk a bit towards the edge of the screen before it starts scrolling in Super Mario Brothers.)

munificent