# Tile based map player movement

I'm doing a tile based 2d rpg in pygame. The problem I'm working on right now is character movement... I am already able to create a map by using multidimensional arrays and a 'camera' follows the player. My problem is now the collision detection... The player should only move one tile at the time so I can easily get his position in tile coordinates and check if he's collided. But I don't know how to do that! At the moment, if a key is pressed, the player moves four pixels in a direction every frame. But that makes tile based collision detection nearly impossible. The player has the size of one tile and yeah, my question is, how can I make the player move only one tile (but NOT every frame since then he would move 32 pixels every single frame.) I know this question was asked before : Pygame Tile Based Character movement speed but this wouldn't work for me, because you had to press the key EVERY TIME you want to move one tile. I use booleans so the player moves as long as the key is pressed.

• "because you had to press the key EVERY TIME you want to move one tile". That's not true at all, I think you are misunderstanding the code sample. Jul 28, 2013 at 11:09
• If you say so... I'm quite sure I did it just the way described there. Jul 28, 2013 at 19:59

To have the snapping effect you need to round down your position to tileX position like with this code (int)(PosX/TileSizeX).